Skip to content

End-application improvements for the tun library use#139

Open
iamtakingiteasy wants to merge 1 commit intoWireGuard:masterfrom
iamtakingiteasy:master
Open

End-application improvements for the tun library use#139
iamtakingiteasy wants to merge 1 commit intoWireGuard:masterfrom
iamtakingiteasy:master

Conversation

@iamtakingiteasy
Copy link

Adds some minor quality of life improvements for other applications relying on the widely ported tun implementation, namely:

  • Adds support for functional options, to provide new options and extend them in the future without affecting the interface contract, as a new variadic argument on CreateTUN should be backwards compatible for current users.
  • Adds option to disable offloads when those are available.
  • Adds support for enforced checksum calculation via functional option, mostly useful to linux with checksum offloading, to avoid double checksum calculation (first in application, then in tun library) when packet manipulation is frequent. Also exposes checksum calculation function to applications and merges src/dst fields to involve larger loop unrolls.
  • Adds support for carrier indication, currently only on linux, via SetCarrier(bool) error on tun.Device and a functional option to provide initial state.
  • Exposes MinOffset() int on tun.Device to indicate required platform-specific offset in buffers to application.

New methods in tun.Device may be breaking to current third-party implementors of this interface, if there are any.

@iamtakingiteasy iamtakingiteasy force-pushed the master branch 2 times, most recently from 2d0f8e2 to 5afb1e0 Compare January 11, 2026 18:53
@iamtakingiteasy
Copy link
Author

Cleanup: removed writeLenBuff added in intermediate revision from non-linux platforms. It is in the stack of ComputeIPChecksumBuffer now.

@iamtakingiteasy
Copy link
Author

iamtakingiteasy commented Jan 16, 2026

Added ICMP checksum support, useful for handling ICMP fragmentation needed and other errors when doing NAT. Checksum of the embedded packet in ICMP body is not handled however and must be updated in separate call, if necessary.

Add backwards-compatible functional options support to native
tun interfaces.

Add support for indicating carrier presence [linux only].
Add `SetCarrier(bool) error` to tun.Device interface for changing
carrier state [linux only].
Add option to create tun device without carrier, or with carrier present
[linux only].

Merge src/dst fields in checksum computation to use larger loop unrolls.
Export checksum functions to applications, add ICMP checksumming.
Add option to disable tun offloads [linux only].
Add option to enforce tun checksum computation for outgoing packets
[all platforms].

Add `MinOffset() int` to tun.Device interface, informing library users of
the required offset.

Signed-off-by: Alexander Tumin <iamtakingiteasy@eientei.org>
@iamtakingiteasy
Copy link
Author

Fixed IPv6 checksum/payload length calculation

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.

1 participant