Skip to content

Conversation

@aaronddavies
Copy link

@aaronddavies aaronddavies commented Dec 8, 2025

Fixes #1095 and #1104.

Changes to operational code:

  • Add the missing IPv4 fixed length fields. They are now a part of the Ipv4Repr struct so that they are no longer dropped when message traffic goes through smoltcp.
  • Add support for options. This implemented as a fixed size byte array to the IPv4Repr struct. The header length field determines how many bytes of the options array are to be included when emitting from the struct. Bench tests showed that a the raw array had better performance than using Option<[u8]>.
  • Filter options across fragments for outgoing packets.
    1. Options are persisted across fragments if the copy bit in the type octet is set.
    2. Option lengths are preserved according to the length octet following the type octet, with the exception of padding octets.
  • Capture the options from an incoming packet. The options of the first incoming fragment of a packet stream are captured as the representative set of options for the final assembled packet, which is to be delivered to the sockets. NOTE: An options capture error in this process will cause the entire packet to be dropped.
  • Fragment packet data in multiples of 8 octets according to RFC 791. The fragment offset for packet fragments is measured in units of 8 octets, therefore payloads must be fragmented in multiples of 8. This adds logic in two places: 1) where the first fragment is sent immediately, and 2) where each successive fragment is sent from the queue.

Changes to unit tests:

  • Update all test IPv4 repr definitions to include the init of the rest of the header fields. This boilerplate is a significant portion of the line changes in this PR.
  • Fix unit tests that don't require fragmentation to not specify fragmentation in their test packet headers
  • Use a config-if block for choosing the right IpvX struct repr
  • Fix some places to only import related modules if features require them
  • Add unit tests for the new changes listed above

NOTE: This PR builds on #1094 and so those changes are also incorporated.

Reference:

  1. RFC 791
  2. IPv4 Parameters - Options

Bench tests before & after

current HEAD main (39cd44e)
test wire::bench_emit_ipv4 ... bench:           8.27 ns/iter (+/- 0.52)
test wire::bench_emit_ipv6 ... bench:           1.11 ns/iter (+/- 0.01)
test wire::bench_emit_tcp  ... bench:          29.89 ns/iter (+/- 0.20)
test wire::bench_emit_udp  ... bench:          25.04 ns/iter (+/- 0.18)


this branch (1bce638)
test wire::bench_emit_ipv4 ... bench:           9.44 ns/iter (+/- 0.54)
test wire::bench_emit_ipv6 ... bench:           1.11 ns/iter (+/- 0.01)
test wire::bench_emit_tcp  ... bench:          29.90 ns/iter (+/- 0.40)
test wire::bench_emit_udp  ... bench:          25.06 ns/iter (+/- 0.44)

aaronddavies and others added 8 commits December 8, 2025 14:33
* add dscp and ecn fields and parse them

* update an instantiation

* claude assisted global fill in

* update unit test with non-zero values to parse

* add remaining fixed fields

* wip - add to all instances

* fix doc test

* fix dont frag flag in tests

* update emit for all fields

* fix icmp test

* update bench test

* fix whitespace
* preserve  header length field

* add options field to ipv4 repr

* update emit function

* add raw socket test

* add raw socket tx test

* update bench test

* if guard

* make options optional

* guard options copy if no options are present

* Revert "guard options copy if no options are present"

This reverts commit 183d062.

* Revert "make options optional"

This reverts commit 556c5c8.

* address comments on constants

* keep header len interface as usize

* cargo fmt

* clean up vector size in unit test and remove unneeded constant

* verify recv queue bytes in test

* add set options method to repr and clean up raw tx unit test

* improve interface between ipv4 packet and repr

* constant for header alignment

---------

Co-authored-by: Jeffrey Moon <[email protected]>
…#6)

* add options len function

* wip - implement options frag filter

* some cleanup

* add guard against no options, add comments

* filter options after first packet is sent

* fix stream id option example in test

* first filter test

* test one option plus fixes

* add bad option test

* add discarded option test

* add more tests

* add comments

* simplify type octet parse

* fix obsolete ipv4repr construct in test

* cargo fmt

* add tx frag option test

* fix magic numbers

* cargo fmt

* clean up tests

* comment

* fix bad assumption of incoming option alignment and only add padding at end

* use enums for option type parsing result

* remove magic numbers

* format

* comment clean up

* use match

* update comment

* tie guards to actual array bounds

* prevent possible panic from bad octet with unit test

* clean up

* remove unnecessary zeroing

* add garbage test

* multifragment test

* test options reassembly of out of order packets

* update comments

* cargo fmt

* drop packet if option filtering fails

* update existing tests with fixes

* adjust test title

* add test to verify message with bad option is never sent

* update comment

* cargo fmt

* rustic fixes
* update rx test with options - fixme - fails

* capture complete set of options in fragment buffer

* cargo fmt

* fix copy

* drop packet on option error
* add options len function

* wip - implement options frag filter

* some cleanup

* add guard against no options, add comments

* filter options after first packet is sent

* fix stream id option example in test

* first filter test

* test one option plus fixes

* add bad option test

* add discarded option test

* add more tests

* add comments

* simplify type octet parse

* fix obsolete ipv4repr construct in test

* cargo fmt

* add tx frag option test

* fix magic numbers

* cargo fmt

* clean up tests

* comment

* fix bad assumption of incoming option alignment and only add padding at end

* use enums for option type parsing result

* remove magic numbers

* format

* comment clean up

* update rx test with options - fixme - fails

* capture complete set of options in fragment buffer

* cargo fmt

* fix copy

* drop packet on option error

* fix tests that dont require fragmentation support

* ipv4 import fixes and ipvx config if block

* import wisely

* repr wisely

* fragment wisely

* format

* fix warnings

* fix merge error

* fix semantic issue introduced in 1095-fragment-options but not detected until ci.sh could be run in thie branch

* fix merge error causing redundant `as`
…ht octets (#10)

* impl

* test

* fix missing adjustment

* coalesce jeff's version - tests dont work yet

* remove argument

* remove non-applicable test

* add max fragment size test

* only add ethernet header length if ethernet is medium

* clean up

* format

* ci test fixes

* update comment

* updated option fragment filter test

* fix merge error
@codecov
Copy link

codecov bot commented Dec 8, 2025

Codecov Report

❌ Patch coverage is 94.38202% with 30 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.96%. Comparing base (39cd44e) to head (30b6272).

Files with missing lines Patch % Lines
src/wire/icmpv4.rs 0.00% 16 Missing ⚠️
src/wire/ipv4.rs 92.94% 11 Missing ⚠️
src/iface/interface/ipv4.rs 93.75% 2 Missing ⚠️
src/iface/fragmentation.rs 99.34% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1108      +/-   ##
==========================================
+ Coverage   80.45%   80.96%   +0.50%     
==========================================
  Files          81       81              
  Lines       24461    24951     +490     
==========================================
+ Hits        19681    20202     +521     
+ Misses       4780     4749      -31     

☔ 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Sending a raw IP packet drops some fields from original IP header

1 participant