Skip to content

Commit b5bee62

Browse files
mikemiles-devmikemiles-devMichael Mileusnich
authored
Added check in variable DataNumber parsing if the field_length is 0. … (#57)
IPFix flowsets now properly calculated. --------- Co-authored-by: mikemiles-dev <[email protected]> Co-authored-by: Michael Mileusnich <[email protected]>
1 parent 452aab7 commit b5bee62

14 files changed

+329
-179
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ mac_address = "1.1.5"
1616
serde = { version = "1.0.166", features = ["derive"] }
1717

1818
[features]
19-
default = []
19+
default = ["parse_unknown_fields"]
2020
unix_timestamp = []
21+
parse_unknown_fields = []
2122

2223
[dev-dependencies]
2324
insta = { version = "1.30.0", features = ["yaml"] }

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ dbg!(parser.v9_parser.options_templates);
6161

6262
To access templates flowset of a processed V9/IPFix flowset you can find the `flowsets` attribute on the Parsed Record. In there you can find `Templates`, `Option Templates`, and `Data` Flowsets.
6363

64+
## Features
65+
66+
* unix_timestamp - Current count since 0000 UTC 1970 as Duration.
67+
* parse_unknown_fields - By default fields not listed in the netflow_parser library will not be parsed and an error is thrown for the packet. When set to true the field will be parsed as a vector of bytes.
68+
6469
## Examples
6570

6671
Some examples has been included mainly for those who want to use this parser to read from a Socket and parse netflow. In those cases with V9/IPFix it is best to create a new parser for each router. There are both single threaded and multi-threaded examples in the examples directory.

RELEASES.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# 0.3.0
2-
* Reworked V9 Parsing. We enforce the length provided by the flow now. Padding is now ignored.
2+
* Reworked IPFIX + V9 Parsing. Flowset length is now used.
3+
* Flow data field Counts are now correctly calculated.
4+
* Added `parse_unknown_fields` feature flag to attempt to parse unknown fields not supported by the library.
5+
* `parse_unknown_fields` is enabled by default.
36

47
# 0.2.9
58
* Fixed parsing issue with V9 flow and padding.

src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@
5959
//! ```
6060
//! To access templates flowset of a processed V9/IPFix flowset you can find the `flowsets` attribute on the Parsed Record. In there you can find `Templates`, `Option Templates`, and `Data` Flowsets.
6161
//!
62+
//! ## Features
63+
//!
64+
//! * unix_timestamp - Current count since 0000 UTC 1970 as Duration.
65+
//! * parse_unknown_fields - By default fields not listed in the netflow_parser library will not be parsed and an error is thrown for the packet. When set to true the field will be parsed as a vector of bytes.
66+
//!
6267
//! ## Examples
6368
//! Some examples has been included mainly for those who want to use this parser to read from a Socket and parse netflow. In those cases with V9/IPFix it is best to create a new parser for each router. There are both single threaded and multi-threaded examples in the examples directory.
6469
//!
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
---
2+
source: src/tests.rs
3+
expression: "NetflowParser::default().parse_bytes(&packet)"
4+
---
5+
- Error:
6+
error_message: "Could not parse v10 packet: Parsing Error: Error { input: [], code: Fail }"
7+
bytes:
8+
- 0
9+
- 10
10+
- 0
11+
- 48
12+
- 1
13+
- 2
14+
- 3
15+
- 4
16+
- 0
17+
- 0
18+
- 0
19+
- 0
20+
- 1
21+
- 2
22+
- 3
23+
- 4
24+
- 0
25+
- 2
26+
- 0
27+
- 20
28+
- 1
29+
- 0
30+
- 0
31+
- 3
32+
- 0
33+
- 8
34+
- 0
35+
- 4
36+
- 0
37+
- 12
38+
- 0
39+
- 4
40+
- 0
41+
- 65
42+
- 0
43+
- 0
44+
- 1
45+
- 0
46+
- 0
47+
- 12
48+
- 1
49+
- 2
50+
- 3
51+
- 4
52+
- 1
53+
- 2
54+
- 3
55+
- 4
56+

src/snapshots/netflow_parser__tests__base_tests__it_parses_ipfix.snap

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,34 +12,39 @@ expression: "NetflowParser::default().parse_bytes(&packet)"
1212
sequence_number: 0
1313
observation_domain_id: 16909060
1414
sets:
15-
- id: 2
16-
length: 20
17-
template:
18-
template_id: 256
19-
field_count: 3
20-
fields:
21-
- field_type_number: 8
22-
field_type: SourceIpv4address
23-
field_length: 4
24-
- field_type_number: 12
25-
field_type: DestinationIpv4address
26-
field_length: 4
27-
- field_type_number: 2
28-
field_type: PacketDeltaCount
29-
field_length: 4
30-
- id: 256
31-
length: 28
32-
data:
33-
data_fields:
34-
- PacketDeltaCount:
35-
DataNumber: 16909058
36-
SourceIpv4address:
37-
Ip4Addr: 1.2.3.4
38-
DestinationIpv4address:
39-
Ip4Addr: 1.2.3.3
40-
- PacketDeltaCount:
41-
DataNumber: 67438087
42-
SourceIpv4address:
43-
Ip4Addr: 0.2.0.2
44-
DestinationIpv4address:
45-
Ip4Addr: 0.1.2.3
15+
- header:
16+
id: 2
17+
length: 20
18+
body:
19+
template:
20+
template_id: 256
21+
field_count: 3
22+
fields:
23+
- field_type_number: 8
24+
field_type: SourceIpv4address
25+
field_length: 4
26+
- field_type_number: 12
27+
field_type: DestinationIpv4address
28+
field_length: 4
29+
- field_type_number: 2
30+
field_type: PacketDeltaCount
31+
field_length: 4
32+
- header:
33+
id: 256
34+
length: 28
35+
body:
36+
data:
37+
data_fields:
38+
- PacketDeltaCount:
39+
DataNumber: 16909058
40+
SourceIpv4address:
41+
Ip4Addr: 1.2.3.4
42+
DestinationIpv4address:
43+
Ip4Addr: 1.2.3.3
44+
- PacketDeltaCount:
45+
DataNumber: 67438087
46+
SourceIpv4address:
47+
Ip4Addr: 0.2.0.2
48+
DestinationIpv4address:
49+
Ip4Addr: 0.1.2.3
50+

src/snapshots/netflow_parser__tests__base_tests__it_parses_ipfix_data_cached_template.snap

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@ expression: parser.parse_bytes(&packet)
1212
sequence_number: 1
1313
observation_domain_id: 0
1414
sets:
15-
- id: 258
16-
length: 10
17-
data:
18-
data_fields:
19-
- PacketDeltaCount:
20-
DataNumber: 8
21-
SourceIpv4address:
22-
Ip4Addr: 0.0.1.1
15+
- header:
16+
id: 258
17+
length: 10
18+
body:
19+
data:
20+
data_fields:
21+
- PacketDeltaCount:
22+
DataNumber: 8
23+
SourceIpv4address:
24+
Ip4Addr: 0.0.1.1
25+

src/snapshots/netflow_parser__tests__base_tests__it_parses_ipfix_options_template.snap

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,23 @@ expression: "NetflowParser::default().parse_bytes(&packet)"
1212
sequence_number: 1
1313
observation_domain_id: 2
1414
sets:
15-
- id: 3
16-
length: 28
17-
options_template:
18-
template_id: 260
19-
field_count: 3
20-
scope_field_count: 1
21-
fields:
22-
- field_type_number: 123
23-
field_type: Enterprise
24-
field_length: 4
25-
enterprise_number: 2
26-
- field_type_number: 32809
27-
field_type: ExportedMessageTotalCount
28-
field_length: 2
29-
- field_type_number: 32810
30-
field_type: ExportedFlowRecordTotalCount
31-
field_length: 2
15+
- header:
16+
id: 3
17+
length: 28
18+
body:
19+
options_template:
20+
template_id: 260
21+
field_count: 3
22+
scope_field_count: 1
23+
fields:
24+
- field_type_number: 123
25+
field_type: Enterprise
26+
field_length: 4
27+
enterprise_number: 2
28+
- field_type_number: 32809
29+
field_type: ExportedMessageTotalCount
30+
field_length: 2
31+
- field_type_number: 32810
32+
field_type: ExportedFlowRecordTotalCount
33+
field_length: 2
34+

src/snapshots/netflow_parser__tests__base_tests__it_parses_ipfix_options_template_with_data.snap

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,36 +12,41 @@ expression: "NetflowParser::default().parse_bytes(&packet)"
1212
sequence_number: 1
1313
observation_domain_id: 2
1414
sets:
15-
- id: 3
16-
length: 28
17-
options_template:
18-
template_id: 260
19-
field_count: 3
20-
scope_field_count: 1
21-
fields:
22-
- field_type_number: 123
23-
field_type: Enterprise
24-
field_length: 4
25-
enterprise_number: 2
26-
- field_type_number: 32809
27-
field_type: ExportedMessageTotalCount
28-
field_length: 2
29-
- field_type_number: 32810
30-
field_type: ExportedFlowRecordTotalCount
31-
field_length: 2
32-
- id: 260
33-
length: 20
34-
options_data:
35-
data_fields:
36-
- ExportedMessageTotalCount:
37-
DataNumber: 276
38-
ExportedFlowRecordTotalCount:
39-
DataNumber: 5140
40-
Enterprise:
41-
DataNumber: 1
42-
- ExportedMessageTotalCount:
43-
DataNumber: 5140
44-
ExportedFlowRecordTotalCount:
45-
DataNumber: 7710
46-
Enterprise:
47-
DataNumber: 2
15+
- header:
16+
id: 3
17+
length: 28
18+
body:
19+
options_template:
20+
template_id: 260
21+
field_count: 3
22+
scope_field_count: 1
23+
fields:
24+
- field_type_number: 123
25+
field_type: Enterprise
26+
field_length: 4
27+
enterprise_number: 2
28+
- field_type_number: 32809
29+
field_type: ExportedMessageTotalCount
30+
field_length: 2
31+
- field_type_number: 32810
32+
field_type: ExportedFlowRecordTotalCount
33+
field_length: 2
34+
- header:
35+
id: 260
36+
length: 20
37+
body:
38+
options_data:
39+
data_fields:
40+
- ExportedMessageTotalCount:
41+
DataNumber: 276
42+
ExportedFlowRecordTotalCount:
43+
DataNumber: 5140
44+
Enterprise:
45+
DataNumber: 1
46+
- ExportedMessageTotalCount:
47+
DataNumber: 5140
48+
ExportedFlowRecordTotalCount:
49+
DataNumber: 7710
50+
Enterprise:
51+
DataNumber: 2
52+

src/snapshots/netflow_parser__tests__base_tests__it_parses_ipfix_with_no_template_fields_raises_error.snap

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,25 @@
22
source: src/tests.rs
33
expression: parser.parse_bytes(&packet)
44
---
5-
- IPFix:
6-
header:
7-
version: 10
8-
length: 26
9-
export_time:
10-
secs: 1
11-
nanos: 0
12-
sequence_number: 1
13-
observation_domain_id: 0
14-
sets: []
155
- Error:
16-
error_message: Unsupported Version
6+
error_message: "Could not parse v10 packet: Parsing Error: Error { input: [0, 8, 0, 0, 1, 1], code: Fail }"
177
bytes:
8+
- 0
9+
- 10
10+
- 0
11+
- 26
12+
- 0
13+
- 0
14+
- 0
15+
- 1
16+
- 0
17+
- 0
18+
- 0
19+
- 1
20+
- 0
21+
- 0
22+
- 0
23+
- 0
1824
- 1
1925
- 2
2026
- 0
@@ -25,3 +31,4 @@ expression: parser.parse_bytes(&packet)
2531
- 0
2632
- 1
2733
- 1
34+

0 commit comments

Comments
 (0)