wireguard

package
v0.0.0-...-7b4befc Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDetectKernel      = errors.New("cannot detect Kernel support")
	ErrCreateTun         = errors.New("cannot create TUN device")
	ErrAddLink           = errors.New("cannot add Wireguard link")
	ErrFindLink          = errors.New("cannot find link")
	ErrFindDevice        = errors.New("cannot find Wireguard device")
	ErrUAPISocketOpening = errors.New("cannot open UAPI socket")
	ErrWgctrlOpen        = errors.New("cannot open wgctrl")
	ErrUAPIListen        = errors.New("cannot listen on UAPI socket")
	ErrAddAddress        = errors.New("cannot add address to wireguard interface")
	ErrConfigure         = errors.New("cannot configure wireguard interface")
	ErrDeviceInfo        = errors.New("cannot get wireguard device information")
	ErrIfaceUp           = errors.New("cannot set the interface to UP")
	ErrRouteAdd          = errors.New("cannot add route for interface")
	ErrDeviceWaited      = errors.New("device waited for")
	ErrKernelSupport     = errors.New("kernel does not support Wireguard")
)
View Source
var (
	ErrInterfaceNameInvalid    = errors.New("invalid interface name")
	ErrPrivateKeyMissing       = errors.New("private key is missing")
	ErrPrivateKeyInvalid       = errors.New("cannot parse private key")
	ErrPublicKeyMissing        = errors.New("public key is missing")
	ErrPublicKeyInvalid        = errors.New("cannot parse public key")
	ErrPreSharedKeyInvalid     = errors.New("cannot parse pre-shared key")
	ErrEndpointAddrMissing     = errors.New("endpoint address is missing")
	ErrEndpointPortMissing     = errors.New("endpoint port is missing")
	ErrAddressMissing          = errors.New("interface address is missing")
	ErrAddressNotValid         = errors.New("interface address is not valid")
	ErrAllowedIPsMissing       = errors.New("allowed IPs are missing")
	ErrAllowedIPNotValid       = errors.New("allowed IP is not valid")
	ErrAllowedIPv6NotSupported = errors.New("allowed IPv6 address not supported")
	ErrFirewallMarkMissing     = errors.New("firewall mark is missing")
	ErrMTUMissing              = errors.New("MTU is missing")
	ErrImplementationInvalid   = errors.New("invalid implementation")
)

Functions

This section is empty.

Types

type Linker

type Linker interface {
	LinkAdd(link netlink.Link) (linkIndex int, err error)
	LinkList() (links []netlink.Link, err error)
	LinkByName(name string) (link netlink.Link, err error)
	LinkSetUp(link netlink.Link) (linkIndex int, err error)
	LinkSetDown(link netlink.Link) error
	LinkDel(link netlink.Link) error
}

type Logger

type Logger interface {
	Debug(s string)
	Debugf(format string, args ...interface{})
	Info(s string)
	Error(s string)
	Errorf(format string, args ...interface{})
}

type NetLinker

type NetLinker interface {
	AddrReplace(link netlink.Link, addr netlink.Addr) error
	Router
	Ruler
	Linker
	IsWireguardSupported() (ok bool, err error)
}

type Router

type Router interface {
	RouteList(family int) (routes []netlink.Route, err error)
	RouteAdd(route netlink.Route) error
}

type Ruler

type Ruler interface {
	RuleAdd(rule netlink.Rule) error
	RuleDel(rule netlink.Rule) error
}

type Settings

type Settings struct {
	// Interface name for the Wireguard interface.
	// It defaults to wg0 if unset.
	InterfaceName string
	// Private key in base 64 format
	PrivateKey string
	// Public key in base 64 format
	PublicKey string
	// Pre shared key in base 64 format
	PreSharedKey string
	// Wireguard server endpoint to connect to.
	Endpoint netip.AddrPort
	// Addresses assigned to the client.
	// Note IPv6 addresses are ignored if IPv6 is not supported.
	Addresses []netip.Prefix
	// AllowedIPs is the IP networks to be routed through
	// the Wireguard interface.
	// Note IPv6 addresses are ignored if IPv6 is not supported.
	AllowedIPs []netip.Prefix
	// FirewallMark to be used in routing tables and IP rules.
	// It defaults to 51820 if left to 0.
	FirewallMark int
	// Maximum Transmission Unit (MTU) setting for the network interface.
	// It defaults to device.DefaultMTU from wireguard-go which is 1420
	MTU uint16
	// RulePriority is the priority for the rule created with the
	// FirewallMark.
	RulePriority int
	// IPv6 can bet set to true if IPv6 should be handled.
	// It defaults to false if left unset.
	IPv6 *bool
	// Implementation is the implementation to use.
	// It can be auto, kernelspace or userspace, and defaults to auto.
	Implementation string
}

func (*Settings) Check

func (s *Settings) Check() (err error)

func (*Settings) SetDefaults

func (s *Settings) SetDefaults()

func (Settings) String

func (s Settings) String() string

func (Settings) ToLines

func (s Settings) ToLines(settings ToLinesSettings) (lines []string)

ToLines serializes the settings to a slice of strings for display.

type ToLinesSettings

type ToLinesSettings struct {
	// Indent defaults to 4 spaces "    ".
	Indent *string
	// FieldPrefix defaults to "├── ".
	FieldPrefix *string
	// LastFieldPrefix defaults to "└── ".
	LastFieldPrefix *string
}

type Wireguard

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

func New

func New(settings Settings, netlink NetLinker,
	logger Logger) (w *Wireguard, err error)

func (*Wireguard) Run

func (w *Wireguard) Run(ctx context.Context, waitError chan<- error, ready chan<- struct{})

See https://git.zx2c4.com/wireguard-go/tree/main.go

Jump to

Keyboard shortcuts

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