smoltcp-rs / smoltcp

a smol tcp/ip stack
BSD Zero Clause License
3.82k stars 433 forks source link

Fix the error of specific length IP packets not being fragmented #1008

Closed Jc0x7D3 closed 4 weeks ago

Jc0x7D3 commented 4 weeks ago

There is an obvious mistake at src/iface/interface/mod.rs:1204: total_ip_len represents the length of the IP packet, while self.caps.max_transmission_unit is the max length of link-layer packets. The correct comparison should be with self.caps.ip_mtu().

When using Medium Ethernet, since self.caps.max_transmission_unit is 14 octets larger than self.caps.ip_mtu(), IP packets with length of 1501~1514 octets should be fragmented, but mistakenly entered the non-fragment branch.

Additionally, I added a test case sending IPv4 packets of different lengths, which can trigger this error.

codecov[bot] commented 4 weeks ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 80.69%. Comparing base (336e7e5) to head (aba9add). Report is 30 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #1008 +/- ## ========================================== - Coverage 80.73% 80.69% -0.05% ========================================== Files 81 81 Lines 28335 28256 -79 ========================================== - Hits 22877 22801 -76 + Misses 5458 5455 -3 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.