conn

package
v0.16.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 7, 2024 License: MPL-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package conn implements WireGuard's network connections.

Index

Constants

View Source
const (
	IdealBatchSize = 128 // maximum number of packets handled per read and write
)

Variables

View Source
var (
	ErrBindAlreadyOpen   = errors.New("bind is already open")
	ErrWrongEndpointType = errors.New("endpoint type does not correspond with bind type")
)

Functions

This section is empty.

Types

type Bind

type Bind interface {
	// Open puts the Bind into a listening state on a given port and reports the actual
	// port that it bound to. Passing zero results in a random selection.
	// fns is the set of functions that will be called to receive packets.
	Open(port uint16) (fns []ReceiveFunc, actualPort uint16, err error)

	// Close closes the Bind listener.
	// All fns returned by Open must return net.ErrClosed after a call to Close.
	Close() error

	// Send writes one or more packets in bufs to address ep. The length of
	// bufs must not exceed BatchSize().
	Send(bufs [][]byte, ep Endpoint) error

	// ParseEndpoint creates a new endpoint from a string.
	ParseEndpoint(s string) (Endpoint, error)

	// BatchSize is the number of buffers expected to be passed to
	// the ReceiveFuncs, and the maximum expected to be passed to SendBatch.
	BatchSize() int
}

A Bind listens on a port for both IPv6 and IPv4 UDP traffic.

A Bind interface may also be a PeekLookAtSocketFd or BindSocketToInterface, depending on the platform-specific implementation.

func NewStdNetBind

func NewStdNetBind() Bind

type Endpoint

type Endpoint interface {
	DstToString() string // returns the destination address (ip:port)
	DstToBytes() []byte  // used for mac2 cookie calculations
	DstIP() netip.Addr
}

An Endpoint maintains the source/destination caching for a peer.

dst: the remote address of a peer ("endpoint" in uapi terminology)
src: the local address from which datagrams originate going to the peer

type ErrUDPGSODisabled

type ErrUDPGSODisabled struct {
	RetryErr error
	// contains filtered or unexported fields
}

func (ErrUDPGSODisabled) Error

func (e ErrUDPGSODisabled) Error() string

func (ErrUDPGSODisabled) Unwrap

func (e ErrUDPGSODisabled) Unwrap() error

type ReceiveFunc

type ReceiveFunc func(packets [][]byte, sizes []int, eps []Endpoint) (n int, err error)

A ReceiveFunc receives at least one packet from the network and writes them into packets. On a successful read it returns the number of elements of sizes, packets, and endpoints that should be evaluated. Some elements of sizes may be zero, and callers should ignore them. Callers must pass a sizes and eps slice with a length greater than or equal to the length of packets. These lengths must not exceed the length of the associated Bind.BatchSize().

func (ReceiveFunc) PrettyName

func (fn ReceiveFunc) PrettyName() string

type StdNetBind

type StdNetBind struct {
	// contains filtered or unexported fields
}

StdNetBind implements Bind for all platforms. While Windows has its own Bind (see bind_windows.go), it may fall back to StdNetBind. TODO: Remove usage of ipv{4,6}.PacketConn when net.UDPConn has comparable methods for sending and receiving multiple datagrams per-syscall. See the proposal in https://github.com/golang/go/issues/45886#issuecomment-1218301564.

func (*StdNetBind) BatchSize

func (s *StdNetBind) BatchSize() int

func (*StdNetBind) Close

func (s *StdNetBind) Close() error

func (*StdNetBind) Open

func (s *StdNetBind) Open(uport uint16) ([]ReceiveFunc, uint16, error)

func (*StdNetBind) ParseEndpoint

func (*StdNetBind) ParseEndpoint(s string) (Endpoint, error)

func (*StdNetBind) Send

func (s *StdNetBind) Send(bufs [][]byte, endpoint Endpoint) error

type StdNetEndpoint

type StdNetEndpoint struct {
	// AddrPort is the endpoint destination.
	netip.AddrPort
}

func (*StdNetEndpoint) DstIP

func (e *StdNetEndpoint) DstIP() netip.Addr

func (*StdNetEndpoint) DstToBytes

func (e *StdNetEndpoint) DstToBytes() []byte

func (*StdNetEndpoint) DstToString

func (e *StdNetEndpoint) DstToString() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL