conn

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: May 14, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package conn implements WireGuard's network connections.

Index

Constants

This section is empty.

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

	// SetMark sets the mark for each packet sent through this Bind.
	// This mark is passed to the kernel as the socket option SO_MARK.
	SetMark(mark uint32) error

	// Send writes a packet b to address ep.
	Send(b []byte, ep Endpoint) error

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

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 NewDefaultBind

func NewDefaultBind() Bind

func NewStdNetBind

func NewStdNetBind() Bind

func NewWinRingBind

func NewWinRingBind() Bind

type BindSocketToInterface

type BindSocketToInterface interface {
	BindSocketToInterface4(interfaceIndex uint32, blackhole bool) error
	BindSocketToInterface6(interfaceIndex uint32, blackhole bool) error
}

BindSocketToInterface is implemented by Bind objects that support being tied to a single network interface. Used by wireguard-windows.

type Endpoint

type Endpoint interface {
	ClearSrc()           // clears the source address
	SrcToString() string // returns the local source address (ip:port)
	DstToString() string // returns the destination address (ip:port)
	DstToBytes() []byte  // used for mac2 cookie calculations
	DstIP() netip.Addr
	SrcIP() 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 PeekLookAtSocketFd

type PeekLookAtSocketFd interface {
	PeekLookAtSocketFd4() (fd int, err error)
	PeekLookAtSocketFd6() (fd int, err error)
}

PeekLookAtSocketFd is implemented by Bind objects that support having their file descriptor peeked at. Used by wireguard-android.

type ReceiveFunc

type ReceiveFunc func(b []byte) (n int, ep Endpoint, err error)

A ReceiveFunc receives a single inbound packet from the network. It writes the data into b. n is the length of the packet. ep is the remote endpoint.

func (ReceiveFunc) PrettyName

func (fn ReceiveFunc) PrettyName() string

type StdNetBind

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

StdNetBind is meant to be a temporary solution on platforms for which the sticky socket / source caching behavior has not yet been implemented. It uses the Go's net package to implement networking. See LinuxSocketBind for a proper implementation on the Linux platform.

func (*StdNetBind) BindSocketToInterface4

func (bind *StdNetBind) BindSocketToInterface4(interfaceIndex uint32, blackhole bool) error

func (*StdNetBind) BindSocketToInterface6

func (bind *StdNetBind) BindSocketToInterface6(interfaceIndex uint32, blackhole bool) error

func (*StdNetBind) Close

func (bind *StdNetBind) Close() error

func (*StdNetBind) Open

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

func (*StdNetBind) ParseEndpoint

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

func (*StdNetBind) Send

func (bind *StdNetBind) Send(buff []byte, endpoint Endpoint) error

func (*StdNetBind) SetMark

func (bind *StdNetBind) SetMark(mark uint32) error

type StdNetEndpoint

type StdNetEndpoint netip.AddrPort

func (StdNetEndpoint) ClearSrc

func (StdNetEndpoint) ClearSrc()

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

func (StdNetEndpoint) SrcIP

func (e StdNetEndpoint) SrcIP() netip.Addr

func (StdNetEndpoint) SrcToString

func (e StdNetEndpoint) SrcToString() string

type WinRingBind

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

WinRingBind uses Windows registered I/O for fast ring buffered networking.

func (*WinRingBind) BindSocketToInterface4

func (bind *WinRingBind) BindSocketToInterface4(interfaceIndex uint32, blackhole bool) error

func (*WinRingBind) BindSocketToInterface6

func (bind *WinRingBind) BindSocketToInterface6(interfaceIndex uint32, blackhole bool) error

func (*WinRingBind) Close

func (bind *WinRingBind) Close() error

func (*WinRingBind) Open

func (bind *WinRingBind) Open(port uint16) (recvFns []ReceiveFunc, selectedPort uint16, err error)

func (*WinRingBind) ParseEndpoint

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

func (*WinRingBind) Send

func (bind *WinRingBind) Send(buf []byte, endpoint Endpoint) error

func (*WinRingBind) SetMark

func (bind *WinRingBind) SetMark(mark uint32) error

type WinRingEndpoint

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

func (*WinRingEndpoint) ClearSrc

func (*WinRingEndpoint) ClearSrc()

func (*WinRingEndpoint) DstIP

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

func (*WinRingEndpoint) DstToBytes

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

func (*WinRingEndpoint) DstToString

func (e *WinRingEndpoint) DstToString() string

func (*WinRingEndpoint) SrcIP

func (e *WinRingEndpoint) SrcIP() netip.Addr

func (*WinRingEndpoint) SrcToString

func (e *WinRingEndpoint) SrcToString() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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