Skip to content

Keep segmented buffers across TUN I/O - #15449

Open
tamird wants to merge 1 commit into
google:masterfrom
tamird:tun-buffer-io
Open

tamird wants to merge 1 commit into
google:masterfrom
tamird:tun-buffer-io

Conversation

@tamird

@tamird tamird commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

The TUN device interface required contiguous Views, copying outgoing
packet segments into one Go heap allocation. Pass Buffers through the
device and its file-description caller, copying only the fixed-size
headers needed to parse incoming packets.

Linux accepts TUN writes beyond the interface MTU. Supporting those
writes with fallible allocation requires retaining storage managed by
the sentry's memory allocator; flattening would copy it back onto the
Go heap. This change prepares that path without changing write limits
or allocation.

Copy reads up to the smaller of the packet and destination sizes, and
preserve copy errors instead of clearing them after a partial transfer.
Use an independent cursor to parse incoming headers before removing
them from the packet buffer.

Assisted-by: Codex

The TUN device interface required contiguous Views, copying outgoing
packet segments into one Go heap allocation. Pass Buffers through the
device and its file-description caller, copying only the fixed-size
headers needed to parse incoming packets.

Linux accepts TUN writes beyond the interface MTU. Supporting those
writes with fallible allocation requires retaining storage managed by
the sentry's memory allocator; flattening would copy it back onto the
Go heap. This change prepares that path without changing write limits
or allocation.

Copy reads up to the smaller of the packet and destination sizes, and
preserve copy errors instead of clearing them after a partial transfer.
Use an independent cursor to parse incoming headers before removing
them from the packet buffer.

Assisted-by: Codex
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.

1 participant