Skip to content

Comments

Implement RFC 815-based IPv4 fragment reassembly#162

Draft
Copilot wants to merge 5 commits intomainfrom
copilot/implement-ipv4-sequence-handling
Draft

Implement RFC 815-based IPv4 fragment reassembly#162
Copilot wants to merge 5 commits intomainfrom
copilot/implement-ipv4-sequence-handling

Conversation

Copy link

Copilot AI commented Nov 13, 2025

The IPv4 fragment handler assumed in-order fragment arrival, violating RFC 791. Fragments arriving out-of-order were dropped.

Changes

RFC 815 Implementation:

  • Implemented RFC 815 hole descriptor algorithm for fragment reassembly
  • Single buffer for complete packet payload instead of HashMap of fragments
  • Hole descriptor list (Vec<Hole>) tracks missing data ranges
  • Pending fragments buffer for fragments arriving before total length is known

Fragment storage:

  • Added FragmentInfo struct with single buffer and hole list (RFC 815)
  • Changed fragment cache from HashMap<Key, Vec<u8>> to HashMap<Key, FragmentInfo>
  • Buffer initialized when last fragment arrives (provides total length)
  • Pending fragments processed once buffer is initialized

Reassembly logic:

  • Hole list updated as each fragment arrives using RFC 815 algorithm
  • Five cases handled: fragment outside hole, completely fills hole, partial fill from left/right, splits hole
  • Reassembly complete when hole list is empty
  • Any fragment can arrive multiple times (no special first-fragment handling)

Duplicate handling:

  • Removed special logic for first fragment
  • RFC 815 naturally handles duplicate fragments by overwriting buffer regions
// Before: HashMap-based with special first-fragment logic
fragments: HashMap<usize, Vec<u8>>
if fragment_offset == 0 && frag_info.fragments.contains_key(&0) {
    frag_info.fragments.clear();
}

// After: RFC 815 single buffer with holes
buffer: Vec<u8>
holes: Vec<Hole>
pending_fragments: Vec<(usize, Vec<u8>)>
// Holes updated per RFC 815 algorithm, no special cases

Test updates:

  • Fixed fragment alignment to 8-byte boundaries (20→16 bytes)
  • Added reverse-order reassembly test (3 fragments: last, middle, first)
  • All existing tests pass with RFC 815 implementation
Original prompt

On ipdltmsgreceiver.rs:1077-1077, Implement the out of order/sequence handling for ipv4 packet handling.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 3 commits November 13, 2025 18:55
Co-authored-by: mbehr1 <3258891+mbehr1@users.noreply.github.com>
Co-authored-by: mbehr1 <3258891+mbehr1@users.noreply.github.com>
…ly logic

Co-authored-by: mbehr1 <3258891+mbehr1@users.noreply.github.com>
Copilot AI changed the title [WIP] Implement out of order handling for IPv4 packets Implement out-of-order IPv4 fragment reassembly Nov 13, 2025
Copilot AI requested a review from mbehr1 November 13, 2025 19:13
@mbehr1
Copy link
Owner

mbehr1 commented Nov 14, 2025

@copilot :
please change the implementation to be based on RFC815:

  • single buffer for the packet payload
  • information which data is available using "holes".

Start with the holes being stored in a separate list/vec.

Allow not just the first packet to be received multiple times but any packet (should be compliant with RFC815). So remove the special logic for the first fragment.

Copy link
Owner

@mbehr1 mbehr1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please change the implementation to be based on RFC815:

single buffer for the packet payload
information which data is available using "holes".
Start with the holes being stored in a separate list/vec.

Allow not just the first packet to be received multiple times but any packet (should be compliant with RFC815). So remove the special logic for the first fragment.

@codecov
Copy link

codecov bot commented Nov 14, 2025

Codecov Report

❌ Patch coverage is 95.88235% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.23%. Comparing base (74cc3fd) to head (0348173).

Files with missing lines Patch % Lines
src/utils/ipdltmsgreceiver.rs 95.88% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #162      +/-   ##
==========================================
+ Coverage   83.03%   83.23%   +0.19%     
==========================================
  Files          40       40              
  Lines       21153    21297     +144     
==========================================
+ Hits        17565    17726     +161     
+ Misses       3588     3571      -17     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@mbehr1 mbehr1 assigned Copilot and unassigned mbehr1 and Copilot Nov 14, 2025
@mbehr1
Copy link
Owner

mbehr1 commented Nov 14, 2025

@copilot can you refactor the changes wit a RFC815 alike solution?

Co-authored-by: mbehr1 <3258891+mbehr1@users.noreply.github.com>
Copy link
Author

Copilot AI commented Nov 14, 2025

@copilot :
please change the implementation to be based on RFC815:

  • single buffer for the packet payload
    ...

Refactored to use RFC 815 algorithm with hole descriptor list in commit e1f2587:

  • Single buffer for packet payload
  • Hole list to track missing data
  • Removed special first-fragment logic (any fragment can be received multiple times)
  • Buffers fragments arriving before last fragment using pending_fragments list

All tests pass.

@copilot can you refactor the changes wit a RFC815 alike solution?

Done in commit e1f2587. The RFC 815 implementation uses:

  • buffer: Vec<u8> - single buffer for packet payload
  • holes: Vec<Hole> - list tracking gaps in received data
  • pending_fragments - stores fragments received before total length is known
  • Hole update algorithm that handles all 5 overlap cases

Removed the HashMap-based approach and first-fragment special logic as requested.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • esm.ubuntu.com
    • Triggering command: /usr/lib/apt/methods/https (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title Implement out-of-order IPv4 fragment reassembly Implement RFC 815-based IPv4 fragment reassembly Nov 14, 2025
Copilot AI requested a review from mbehr1 November 14, 2025 16:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants