transport layer size calculation fix #217
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes to Transport Layer Size Calculations
This PR addresses inconsistencies and ambiguities in the size calculations for UDP and TCP protocols in NFStream, specifically regarding
transport_size(accounting mode 2) andpayload_size(accounting mode 3). Additionally, the fixes ensure alignment with ICMP and ICMPv6 calculations for consistency across all protocols.1. Fix for UDP
Observation
When accounting mode was set to:
This rendered mode 2 redundant, as it was essentially duplicating mode 3. I believe the original intent was to keep the UDP header length in the size value, not to subtract it.
Fix
transport_size(accounting mode 2): Now includes the UDP header along with the payload.payload_size(accounting mode 3): Remains unchanged and represents the payload-only size, excluding the UDP header.Why This Fix Is Better
2. Fix for TCP
Observation
The original implementation calculated sizes as follows:
This approach created ambiguity, especially since:
Fix
transport_size(accounting mode 2): Now includes the entire TCP segment (base header + options + payload), ensuring that the full transport size is reported.payload_size(accounting mode 3): Continues to represent the raw payload size, excluding all headers.Why This Fix Is Better
transport_sizeinclude their respective headers.2(transport size).3(payload size).3. Extension to ICMP and ICMPv6
Observation
Previously,
transport_sizecalculations for ICMP and ICMPv6 also excluded their respective headers.Fix
transport_sizenow includes the header size for both ICMP and ICMPv6.payload_sizecontinues to represent only the data payload.This ensures all protocols (TCP, UDP, ICMP, ICMPv6) follow a unified metric definition, simplifying analysis.
Type of change
How Has This Been Tested?
A simple PCAP with TCP/UDP flows is enough for testing and comparison. Having TCP options is preferred. Testing focused on examining the sizes before and after the fix. The included
test.pywas also run to verify the fix does not break anything.