Skip to content

Conversation

@jwhited
Copy link
Member

@jwhited jwhited commented May 21, 2025

This enables a conn.Bind to leverage wireguard-go packet memory for reading packets containing layers that wireguard-go should ignore, e.g. a VXLAN or Geneve header preceeding WireGuard.

@jwhited jwhited requested review from bradfitz and raggi May 21, 2025 22:21
Copy link

@sfllaw sfllaw left a comment

Choose a reason for hiding this comment

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

Just some notes about sources of confusion from someone unfamiliar with this codebase. Feel free to ignore.

Comment on lines +24 to +25
// sizes, packets, and endpoints that should be evaluated. A sizes element
// includes both the starting and ending offset for an element of packets. Some
Copy link

Choose a reason for hiding this comment

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

❓ Confused: Is the sizes element defined as [start, end)? It would be nice if the documentation were more explicit about ranges.

❓ Confused: Is this the name sizes still the right name for this, now that it is some kind of range or interval? Granted, I cannot come up with a better name.

Copy link
Member

@danderson danderson left a comment

Choose a reason for hiding this comment

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

LGTM. Reflecting some discussion off-github: we're balancing extending the functionality of this API for a pressing need, vs. doing a larger scale refactor to improve the packet wrangling API as a whole.

The latter is tempting, but is likely to spiral into a large change as it bubbles through more of the API. We'd rather tackle a broader redesign separately (and we're gearing up to, available bandwidth notwithstanding), rather than end up pulling refactors into this targeted feature change.

msg := &(*msgs)[i]
sizes[i] = msg.N
if sizes[i] == 0 {
sizes[i][0], sizes[i][1] = 0, msg.N
Copy link
Member

Choose a reason for hiding this comment

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

minor suggestion, optional: move the continue branch below further up, and make the condition look at msg.N instead of the sizes array? As written here it took me a beat to translate the branch condition to "oh, skip empty messages".

Copy link
Member Author

Choose a reason for hiding this comment

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

Suggestion SGTM. I'm leaving it as-is to reduce drift/differing LoC from upstream for this conn.Bind implementation that we don't use.

@jwhited jwhited force-pushed the jwhited/read-start-offset branch from 8c59ede to 0924732 Compare May 29, 2025 03:05
This enables a conn.Bind to leverage wireguard-go packet memory for
reading packets containing layers that wireguard-go should ignore, e.g.
a VXLAN or Geneve header preceeding WireGuard.

Signed-off-by: Jordan Whited <jordan@tailscale.com>
@jwhited jwhited force-pushed the jwhited/read-start-offset branch from 0924732 to fd2c830 Compare May 29, 2025 18:35
@jwhited
Copy link
Member Author

jwhited commented May 30, 2025

As-is this commit doesn't account for the extra 8 bytes on the TUN write side of the packet pipeline, which is a bug. Tests pass because there is no test exercising a nonzero receive offset.

Addressing this likely requires adding a field to QueueInboundElement accounting for the offset, as a conn.Bind may selectively pass a nonzero offset. We don't want to always assume an extra 8 bytes at the packet head. A conn.Bind may receive packets with or without an encapsulating transport on the same socket/ReceiveFunc.

Closing this for now until there's time to revisit. We can have the conn.Bind copy/memmove away the Geneve header for now until that performance penalty is worth addressing.

@jwhited jwhited closed this May 30, 2025
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