Skip to content

feat(phy): add TCP segmentation support#1

Open
cagatay-y wants to merge 2 commits intohermit-os:mainfrom
cagatay-y:segmentation-offload
Open

feat(phy): add TCP segmentation support#1
cagatay-y wants to merge 2 commits intohermit-os:mainfrom
cagatay-y:segmentation-offload

Conversation

@cagatay-y
Copy link
Copy Markdown

@cagatay-y cagatay-y commented Mar 10, 2026

The Windows and Linux documentations for the same feature were used as references. It was more difficult to find information on how devices support the feature, so the interface is mostly based on how virtio-net devices expect to be driven. The code was tested on the Hermit kernel with a virtio-net device, but only with IPv4, as Hermit does not support IPv6.

Design rationale

  • The segmentation capabilities are specified separately for TCP on IPv4 and IPv6. This follows the example of Linux and Windows. This should provide flexibility for devices that support only one of the IP versions and should not be a problem for devices that support both as a single feature.
  • As it is necessary to communicate to the device what the target segment size is, a field is added to PacketMeta. To keep the compiler able to optimise out the structure if the features associated with the fields, the segmentation offload feature is optional, following the example of packetmeta-id.
  • For pre-segmentation IP packets whose size exceeds the maximum that is allowed by the length field of the IP header, we fall back to zero. An alternative would be to set the field to zero unconditionally, and this seems to be a "should" level expectation for at least for some Intel cards. The fallback approach has the advantage of keeping code that uses the IP header field (for example for constructing TcpPackets to set the partial checksum in our case) functional for sufficiently small unsegmented packets. On the other hand, it can also be argued that causing a failure even for smaller packets can help uncover the error case with the larger packets earlier in the development of the device drivers.

Comparison to smoltcp-rs#830

  • The segmentation capabilities struct in the older PR follows the structure of ChecksumCapabilities. This PR does not do so for the following reasons:
    • The segmentation capability for a given protocol is not binary. Different devices may support large (i.e. unsegmented) packets of different maximum sizes (references for various devices)
    • On the receive side the related feature seems to be called "coalescing." It may be somewhat confusing to represent information for the receive side in a structure whose name refers to "segmentation."
  • The capability structure is named SegmentationCapabilities rather than the TCP specific name TsoCapabilities. I believe the current structure can be expanded to support UDP, though I currently do not have a prototype for that.
  • The current PR has support for communicating the target segment size to the device.

@mkroening mkroening self-assigned this Mar 11, 2026
Copy link
Copy Markdown
Member

@mkroening mkroening left a comment

Choose a reason for hiding this comment

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

The code looks good to me, though I am not too familiar with smoltcp's internals.

The PR could use a description discussing the design and differentiating itself from smoltcp-rs#830, though.

Furthermore, CI does not pass at the moment.

I have updated our fork, so if you force-push, the commits should show up more nicely.

@cagatay-y cagatay-y force-pushed the segmentation-offload branch from 66cbb06 to 4e99514 Compare March 11, 2026 14:49
@codecov-commenter
Copy link
Copy Markdown

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

Thanks for integrating Codecov - We've got you covered ☂️

@cagatay-y cagatay-y force-pushed the segmentation-offload branch 4 times, most recently from 577b356 to 1f2bb37 Compare March 17, 2026 17:27
@cagatay-y cagatay-y force-pushed the segmentation-offload branch 2 times, most recently from f4a6220 to a8877fc Compare April 9, 2026 20:01
cagatay-y added 2 commits May 5, 2026 17:08
It is possible for packets larger than the current capture limits to be
sent with the segmentation offload feature.
@cagatay-y cagatay-y force-pushed the segmentation-offload branch from a8877fc to 1b220b0 Compare May 5, 2026 15:09
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.

3 participants