wireguard

package
v0.0.0-...-f021cd2 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultMTU = 1420

DefaultMTU is the the default MTU used by WireGuard.

Variables

This section is empty.

Functions

func New

func New(name string, mtu uint) (int, bool, error)

New returns a WireGuard interface with the given name. If the interface exists, its index is returned. Otherwise, a new interface is created. The function also returns a boolean to indicate if the interface was created.

Types

type Conf

type Conf struct {
	wgtypes.Config
	// The Peers field is shadowed because every Peer needs the Endpoint field that contains a DNS endpoint.
	Peers []Peer
}

Conf represents a WireGuard configuration file.

func (*Conf) Bytes

func (c *Conf) Bytes() ([]byte, error)

Bytes renders a WireGuard configuration to bytes.

func (*Conf) Equal

func (c *Conf) Equal(d *wgtypes.Device) (bool, string)

Equal returns true if the Conf and wgtypes.Device are equal.

func (*Conf) WGConfig

func (c *Conf) WGConfig() wgtypes.Config

WGConfig returns a wgytpes.Config from a Conf.

type Endpoint

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

Endpoint represents a WireGuard endpoint.

func NewEndpoint

func NewEndpoint(ip net.IP, port int) *Endpoint

NewEndpoint returns an Endpoint from a net.IP and port.

func NewEndpointFromUDPAddr

func NewEndpointFromUDPAddr(u *net.UDPAddr) *Endpoint

NewEndpointFromUDPAddr returns an Endpoint from a net.UDPAddr.

func ParseEndpoint

func ParseEndpoint(endpoint string) *Endpoint

ParseEndpoint returns an Endpoint from a string. The input should look like "10.0.0.0:100", "[ff10::10]:100" or "example.com:100".

func (*Endpoint) DNS

func (e *Endpoint) DNS() string

DNS returns the DN of the Endpoint.

func (*Endpoint) Equal

func (e *Endpoint) Equal(b *Endpoint, dnsFirst bool) bool

Equal will return true, if the Enpoints are equal. If dnsFirst is false, the DN will only be compared if the IPs are nil.

func (*Endpoint) HasDNS

func (e *Endpoint) HasDNS() bool

HasDNS returns true if the endpoint has a DN.

func (*Endpoint) IP

func (e *Endpoint) IP() net.IP

IP returns the IP address of the Enpoint or nil.

func (*Endpoint) Port

func (e *Endpoint) Port() int

Port returns the port of the Endpoint.

func (*Endpoint) Ready

func (e *Endpoint) Ready() bool

Ready return true, if the Enpoint is ready. Ready means that an IP or DN and port exists.

func (*Endpoint) Resolved

func (e *Endpoint) Resolved() bool

Resolved returns true, if the DN of the Endpoint was resolved or if the Endpoint has a resolved endpoint.

func (*Endpoint) String

func (e *Endpoint) String() string

String will return the endpoint as a string. If a DN exists, it will take prcedence over the resolved endpoint.

func (*Endpoint) StringOpt

func (e *Endpoint) StringOpt(dnsFirst bool) string

StringOpt will return the string of the Endpoint. If dnsFirst is false, the resolved Endpoint will take precedence over the DN.

func (*Endpoint) UDPAddr

func (e *Endpoint) UDPAddr(resolve bool) (*net.UDPAddr, error)

UDPAddr returns the UDPAddr of the Endpoint. If resolve is false, UDPAddr() will not try to resolve a DN name, if the Endpoint is not yet resolved.

type Peer

type Peer struct {
	wgtypes.PeerConfig
	Endpoint *Endpoint
}

Peer represents a `peer` section of a WireGuard configuration.

func (*Peer) DeduplicateIPs

func (p *Peer) DeduplicateIPs()

DeduplicateIPs eliminates duplicate allowed IPs.

Jump to

Keyboard shortcuts

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