Documentation
¶
Index ¶
- Constants
- Variables
- type Endpoint
- type MagicResponseCallback
- type PacketSource
- type SharedBind
- func (b *SharedBind) AddRef()
- func (b *SharedBind) BatchSize() int
- func (b *SharedBind) ClearNetstackConn()
- func (b *SharedBind) Close() error
- func (b *SharedBind) GetNetstackConn() net.PacketConn
- func (b *SharedBind) GetRefCount() int32
- func (b *SharedBind) GetUDPConn() *net.UDPConn
- func (b *SharedBind) InjectPacket(data []byte, fromAddr netip.AddrPort) error
- func (b *SharedBind) IsClosed() bool
- func (b *SharedBind) Open(uport uint16) ([]wgConn.ReceiveFunc, uint16, error)
- func (b *SharedBind) ParseEndpoint(s string) (wgConn.Endpoint, error)
- func (b *SharedBind) Release() error
- func (b *SharedBind) Send(bufs [][]byte, ep wgConn.Endpoint) error
- func (b *SharedBind) SetMagicResponseCallback(callback MagicResponseCallback)
- func (b *SharedBind) SetMark(mark uint32) error
- func (b *SharedBind) SetNetstackConn(conn net.PacketConn)
- func (b *SharedBind) WriteToUDP(data []byte, addr *net.UDPAddr) (int, error)
- type SourceAwareEndpoint
Constants ¶
const ( // MagicPacketDataLen is the length of random data included in test packets MagicPacketDataLen = 8 // MagicTestRequestLen is the total length of a test request packet MagicTestRequestLen = 17 + MagicPacketDataLen // len("PANGOLIN_TEST_REQ") + 8 // MagicTestResponseLen is the total length of a test response packet MagicTestResponseLen = 17 + MagicPacketDataLen // len("PANGOLIN_TEST_RSP") + 8 )
Variables ¶
var ( // MagicTestRequest is the prefix for a test request packet // Format: PANGOLIN_TEST_REQ + 8 bytes of random data (for echo) MagicTestRequest = []byte("PANGOLIN_TEST_REQ") // MagicTestResponse is the prefix for a test response packet // Format: PANGOLIN_TEST_RSP + 8 bytes echoed from request MagicTestResponse = []byte("PANGOLIN_TEST_RSP") )
Magic packet constants for connection testing These packets are intercepted by SharedBind and responded to directly, without being passed to the WireGuard device.
Functions ¶
This section is empty.
Types ¶
type Endpoint ¶
Endpoint represents a network endpoint for the SharedBind
func (*Endpoint) ClearSrc ¶
func (e *Endpoint) ClearSrc()
ClearSrc implements the wgConn.Endpoint interface
func (*Endpoint) DstToBytes ¶
DstToBytes implements the wgConn.Endpoint interface
func (*Endpoint) DstToString ¶
DstToString implements the wgConn.Endpoint interface
func (*Endpoint) SrcToString ¶
SrcToString implements the wgConn.Endpoint interface
type MagicResponseCallback ¶
MagicResponseCallback is the function signature for magic packet response callbacks
type PacketSource ¶
type PacketSource uint8
PacketSource identifies where a packet came from
const ( SourceSocket PacketSource = iota // From physical UDP socket (hole-punched clients) SourceNetstack // From netstack (relay through main tunnel) )
type SharedBind ¶
type SharedBind struct {
// contains filtered or unexported fields
}
SharedBind is a thread-safe UDP bind that can be shared between WireGuard and hole punch senders. It wraps a single UDP connection and implements reference counting to prevent premature closure. It also supports receiving packets from a netstack and routing responses back through the appropriate source.
func New ¶
func New(udpConn *net.UDPConn) (*SharedBind, error)
New creates a new SharedBind from an existing UDP connection. The SharedBind takes ownership of the connection and will close it when all references are released.
func (*SharedBind) AddRef ¶
func (b *SharedBind) AddRef()
AddRef increments the reference count. Call this when sharing the bind with another component.
func (*SharedBind) BatchSize ¶
func (b *SharedBind) BatchSize() int
BatchSize returns the preferred batch size for sending packets.
func (*SharedBind) ClearNetstackConn ¶
func (b *SharedBind) ClearNetstackConn()
ClearNetstackConn clears the netstack connection and tracked endpoints. Call this when stopping the relay.
func (*SharedBind) Close ¶
func (b *SharedBind) Close() error
Close implements the WireGuard Bind interface. It decrements the reference count and closes the connection if no references remain.
func (*SharedBind) GetNetstackConn ¶
func (b *SharedBind) GetNetstackConn() net.PacketConn
GetNetstackConn returns the netstack connection if set
func (*SharedBind) GetRefCount ¶
func (b *SharedBind) GetRefCount() int32
GetRefCount returns the current reference count (for debugging)
func (*SharedBind) GetUDPConn ¶
func (b *SharedBind) GetUDPConn() *net.UDPConn
GetUDPConn returns the underlying UDP connection. The caller must not close this connection directly.
func (*SharedBind) InjectPacket ¶
func (b *SharedBind) InjectPacket(data []byte, fromAddr netip.AddrPort) error
InjectPacket allows injecting a packet directly into the SharedBind's receive path. This is used for direct relay from netstack without going through the host network. The fromAddr should be the address the packet appears to come from.
func (*SharedBind) IsClosed ¶
func (b *SharedBind) IsClosed() bool
IsClosed returns whether the bind is closed
func (*SharedBind) Open ¶
func (b *SharedBind) Open(uport uint16) ([]wgConn.ReceiveFunc, uint16, error)
Open implements the WireGuard Bind interface. Since the connection is already open, this just sets up the receive functions.
func (*SharedBind) ParseEndpoint ¶
func (b *SharedBind) ParseEndpoint(s string) (wgConn.Endpoint, error)
ParseEndpoint creates a new endpoint from a string address.
func (*SharedBind) Release ¶
func (b *SharedBind) Release() error
Release decrements the reference count. When it reaches zero, the underlying UDP connection is closed.
func (*SharedBind) Send ¶
func (b *SharedBind) Send(bufs [][]byte, ep wgConn.Endpoint) error
Send implements the WireGuard Bind interface. It sends packets to the specified endpoint, routing through the appropriate source (netstack or physical socket) based on where the endpoint's packets came from.
func (*SharedBind) SetMagicResponseCallback ¶
func (b *SharedBind) SetMagicResponseCallback(callback MagicResponseCallback)
SetMagicResponseCallback sets a callback function that will be called when a magic test response packet is received. This is used for holepunch testing. Pass nil to clear the callback.
func (*SharedBind) SetMark ¶
func (b *SharedBind) SetMark(mark uint32) error
SetMark implements the WireGuard Bind interface. It's a no-op for this implementation.
func (*SharedBind) SetNetstackConn ¶
func (b *SharedBind) SetNetstackConn(conn net.PacketConn)
SetNetstackConn sets the netstack connection for receiving/sending packets through the tunnel. This connection is used for relay traffic that should go back through the main tunnel.
func (*SharedBind) WriteToUDP ¶
WriteToUDP writes data to a specific UDP address. This is thread-safe and can be used by hole punch senders.
type SourceAwareEndpoint ¶
SourceAwareEndpoint wraps an endpoint with source information
func (*SourceAwareEndpoint) GetSource ¶
func (e *SourceAwareEndpoint) GetSource() PacketSource
GetSource returns the source of this endpoint