wg

package
v0.4.10 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2024 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Overview

Package wg provides various helpers for WireGuard

Index

Constants

View Source
const (
	SocketPath = "/var/run/wireguard"
	ConfigPath = "/etc/wireguard"

	DefaultPort = 51820

	TunnelOverhead = 80 // Byte
	DefaultMTU     = 1500 - TunnelOverhead
	MinimalMTU     = 1280 // Byte for minimal IPv6 MTU
)

Variables

View Source
var ErrNoConn = errors.New("no connection for endpoint")

Functions

func CleanupUserSockets

func CleanupUserSockets() error

func CmpDevices

func CmpDevices(a, b wgtypes.Device) int

func CmpPeerHandshakeTime

func CmpPeerHandshakeTime(a, b wgtypes.Peer) int

func CmpPeers

func CmpPeers(a, b wgtypes.Peer) int

func KernelModuleExists

func KernelModuleExists() bool

func SetMark

func SetMark(conn net.PacketConn, mark uint32) error

Types

type Bind

type Bind struct {
	Conns []BindConn
	// contains filtered or unexported fields
}

func NewBind

func NewBind(logger *log.Logger) *Bind

func (*Bind) AddConn

func (b *Bind) AddConn(conn net.PacketConn)

func (*Bind) AddOpenHandler

func (b *Bind) AddOpenHandler(h BindHandler)

func (*Bind) AddPacketHandler

func (b *Bind) AddPacketHandler(h netx.PacketHandler)

func (*Bind) BatchSize

func (b *Bind) BatchSize() int

BatchSize is the number of buffers expected to be passed to the ReceiveFuncs, and the maximum expected to be passed to SendBatch. Implements wgconn.Bind

func (*Bind) Close

func (b *Bind) Close() error

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

func (*Bind) Endpoint

func (b *Bind) Endpoint(ap netip.AddrPort) *BindEndpoint

Endpoint returns an Endpoint containing ap.

func (*Bind) Open

func (b *Bind) Open(port uint16) ([]wgconn.ReceiveFunc, uint16, error)

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.

func (*Bind) ParseEndpoint

func (b *Bind) ParseEndpoint(s string) (ep wgconn.Endpoint, err error)

ParseEndpoint creates a new endpoint from a string. Implements wgconn.Bind

func (*Bind) RemoveOpenHandler

func (b *Bind) RemoveOpenHandler(h BindHandler)

func (*Bind) RemovePacketHandler

func (b *Bind) RemovePacketHandler(h netx.PacketHandler)

func (*Bind) Send

func (b *Bind) Send(packets [][]byte, cep wgconn.Endpoint) error

Send writes a packet to an endpoint.

func (*Bind) SetMark

func (b *Bind) SetMark(mark uint32) 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.

type BindConn

type BindConn interface {
	Receive(buf []byte) (int, wgconn.Endpoint, error)
	Send(buf []byte, ep wgconn.Endpoint) (int, error)

	ListenPort() (uint16, bool)
	SetMark(mark uint32) error

	BindClose() error
}

type BindEndpoint

type BindEndpoint struct {
	netip.AddrPort

	Conn BindConn
}

func (BindEndpoint) ClearSrc

func (BindEndpoint) ClearSrc()

func (BindEndpoint) DstIP

func (ep BindEndpoint) DstIP() netip.Addr

func (BindEndpoint) DstToBytes

func (ep BindEndpoint) DstToBytes() []byte

func (BindEndpoint) DstToString

func (ep BindEndpoint) DstToString() string

func (BindEndpoint) DstUDPAddr

func (ep BindEndpoint) DstUDPAddr() *net.UDPAddr

func (BindEndpoint) SrcIP

func (ep BindEndpoint) SrcIP() netip.Addr

func (BindEndpoint) SrcToString

func (ep BindEndpoint) SrcToString() string

type BindHandler

type BindHandler interface {
	OnBindOpen(b *Bind, port uint16)
}

type BindKernelConn

type BindKernelConn interface {
	BindConn

	WriteKernel([]byte) (int, error)
}

BindKernelConn is a BindConn which is consumed by a Kernel WireGuard interface

type Config

type Config struct {
	wgtypes.Config

	PeerEndpoints []string
	PeerNames     []string

	Address    []net.IPNet
	DNS        []net.IPAddr
	MTU        *int
	Table      *string
	PreUp      []string
	PreDown    []string
	PostUp     []string
	PostDown   []string
	SaveConfig *bool
}

func ParseConfig

func ParseConfig(data []byte) (*Config, error)

func (*Config) Dump

func (cfg *Config) Dump(wr io.Writer) error

type Interface

type Interface wgtypes.Device

func (*Interface) Config

func (d *Interface) Config() *Config

func (*Interface) Dump

func (d *Interface) Dump(wr io.Writer, hideKeys bool) error

func (*Interface) DumpEnv

func (d *Interface) DumpEnv(wr io.Writer) error

Directories

Path Synopsis
tracer
kernel
Package kernel defines some constants of the Kernel version and arch for which the code has been generated
Package kernel defines some constants of the Kernel version and arch for which the code has been generated

Jump to

Keyboard shortcuts

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