Documentation ¶
Overview ¶
Package conn implements WireGuard's network connections.
Index ¶
- Variables
- type Bind
- type BindSocketToInterface
- type Endpoint
- type LinuxSocketBind
- func (bind *LinuxSocketBind) Close() error
- func (bind *LinuxSocketBind) Open(port uint16) (uint16, error)
- func (*LinuxSocketBind) ParseEndpoint(s string) (Endpoint, error)
- func (bind *LinuxSocketBind) ReceiveIPv4(buff []byte) (int, Endpoint, error)
- func (bind *LinuxSocketBind) ReceiveIPv6(buff []byte) (int, Endpoint, error)
- func (bind *LinuxSocketBind) Send(buff []byte, end Endpoint) error
- func (bind *LinuxSocketBind) SetMark(value uint32) error
- type LinuxSocketEndpoint
- func (end *LinuxSocketEndpoint) ClearDst()
- func (end *LinuxSocketEndpoint) ClearSrc()
- func (endpoint *LinuxSocketEndpoint) Dst4() *unix.SockaddrInet4
- func (end *LinuxSocketEndpoint) DstIP() net.IP
- func (end *LinuxSocketEndpoint) DstToBytes() []byte
- func (end *LinuxSocketEndpoint) DstToString() string
- func (endpoint *LinuxSocketEndpoint) IsV6() bool
- func (endpoint *LinuxSocketEndpoint) Src4() *ipv4Source
- func (end *LinuxSocketEndpoint) SrcIP() net.IP
- func (end *LinuxSocketEndpoint) SrcToString() string
- type PeekLookAtSocketFd
- type StdNetBind
- func (bind *StdNetBind) Close() error
- func (bind *StdNetBind) Open(uport uint16) (uint16, error)
- func (*StdNetBind) ParseEndpoint(s string) (Endpoint, error)
- func (bind *StdNetBind) ReceiveIPv4(buff []byte) (int, Endpoint, error)
- func (bind *StdNetBind) ReceiveIPv6(buff []byte) (int, Endpoint, error)
- func (bind *StdNetBind) Send(buff []byte, endpoint Endpoint) error
- func (bind *StdNetBind) SetMark(mark uint32) error
- type StdNetEndpoint
Constants ¶
This section is empty.
Variables ¶
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. Open(port uint16) (actualPort uint16, err error) // Close closes the Bind listener. 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 // ReceiveIPv6 reads an IPv6 UDP packet into b. It reports the number of bytes read, // n, the packet source address ep, and any error. ReceiveIPv6(b []byte) (n int, ep Endpoint, err error) // ReceiveIPv4 reads an IPv4 UDP packet into b. It reports the number of bytes read, // n, the packet source address ep, and any error. ReceiveIPv4(b []byte) (n int, ep Endpoint, err 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 NewLinuxSocketBind ¶
func NewLinuxSocketBind() Bind
func NewStdNetBind ¶
func NewStdNetBind() 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() net.IP SrcIP() net.IP }
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 LinuxSocketBind ¶
type LinuxSocketBind struct {
// contains filtered or unexported fields
}
LinuxSocketBind uses sendmsg and recvmsg to implement a full bind with sticky sockets on Linux.
func (*LinuxSocketBind) Close ¶
func (bind *LinuxSocketBind) Close() error
func (*LinuxSocketBind) ParseEndpoint ¶
func (*LinuxSocketBind) ParseEndpoint(s string) (Endpoint, error)
func (*LinuxSocketBind) ReceiveIPv4 ¶
func (bind *LinuxSocketBind) ReceiveIPv4(buff []byte) (int, Endpoint, error)
func (*LinuxSocketBind) ReceiveIPv6 ¶
func (bind *LinuxSocketBind) ReceiveIPv6(buff []byte) (int, Endpoint, error)
func (*LinuxSocketBind) SetMark ¶
func (bind *LinuxSocketBind) SetMark(value uint32) error
type LinuxSocketEndpoint ¶
type LinuxSocketEndpoint struct {
// contains filtered or unexported fields
}
func (*LinuxSocketEndpoint) ClearDst ¶
func (end *LinuxSocketEndpoint) ClearDst()
func (*LinuxSocketEndpoint) ClearSrc ¶
func (end *LinuxSocketEndpoint) ClearSrc()
func (*LinuxSocketEndpoint) Dst4 ¶
func (endpoint *LinuxSocketEndpoint) Dst4() *unix.SockaddrInet4
func (*LinuxSocketEndpoint) DstIP ¶
func (end *LinuxSocketEndpoint) DstIP() net.IP
func (*LinuxSocketEndpoint) DstToBytes ¶
func (end *LinuxSocketEndpoint) DstToBytes() []byte
func (*LinuxSocketEndpoint) DstToString ¶
func (end *LinuxSocketEndpoint) DstToString() string
func (*LinuxSocketEndpoint) IsV6 ¶
func (endpoint *LinuxSocketEndpoint) IsV6() bool
func (*LinuxSocketEndpoint) Src4 ¶
func (endpoint *LinuxSocketEndpoint) Src4() *ipv4Source
func (*LinuxSocketEndpoint) SrcIP ¶
func (end *LinuxSocketEndpoint) SrcIP() net.IP
func (*LinuxSocketEndpoint) SrcToString ¶
func (end *LinuxSocketEndpoint) SrcToString() string
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 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) Close ¶
func (bind *StdNetBind) Close() error
func (*StdNetBind) ParseEndpoint ¶
func (*StdNetBind) ParseEndpoint(s string) (Endpoint, error)
func (*StdNetBind) ReceiveIPv4 ¶
func (bind *StdNetBind) ReceiveIPv4(buff []byte) (int, Endpoint, error)
func (*StdNetBind) ReceiveIPv6 ¶
func (bind *StdNetBind) ReceiveIPv6(buff []byte) (int, Endpoint, error)
func (*StdNetBind) SetMark ¶
func (bind *StdNetBind) SetMark(mark uint32) error
type StdNetEndpoint ¶
func (*StdNetEndpoint) ClearSrc ¶
func (*StdNetEndpoint) ClearSrc()
func (*StdNetEndpoint) DstIP ¶
func (e *StdNetEndpoint) DstIP() net.IP
func (*StdNetEndpoint) DstToBytes ¶
func (e *StdNetEndpoint) DstToBytes() []byte
func (*StdNetEndpoint) DstToString ¶
func (e *StdNetEndpoint) DstToString() string
func (*StdNetEndpoint) SrcIP ¶
func (e *StdNetEndpoint) SrcIP() net.IP
func (*StdNetEndpoint) SrcToString ¶
func (e *StdNetEndpoint) SrcToString() string