Version: v0.0.0-...-df8d1ab Latest Latest

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

Go to latest
Published: Sep 10, 2021 License: Apache-2.0 Imports: 12 Imported by: 0




View Source
const DefaultMTU = 1420

DefaultMTU is the the default MTU used by WireGuard.


This section is empty.


func GenKey

func GenKey() ([]byte, error)

GenKey generates a WireGuard private key.

func Keys

func Keys() ([]byte, []byte, error)

Keys generates a WireGuard private and public key-pair.

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.

func PubKey

func PubKey(key []byte) ([]byte, error)

PubKey generates a WireGuard public key for a given private key.

func SetConf

func SetConf(iface string, path string) error

SetConf applies a WireGuard configuration file to the given interface.

func ShowConf

func ShowConf(iface string) ([]byte, error)

ShowConf gets the WireGuard configuration for the given interface.

func ShowDump

func ShowDump(iface string) ([]byte, error)

ShowDump gets the WireGuard configuration and runtime information for the given interface.


type Conf

type Conf struct {
	Interface *Interface
	Peers     []*Peer

Conf represents a WireGuard configuration file.

func Parse

func Parse(buf []byte) *Conf

Parse parses a given WireGuard configuration file and produces a Conf struct.

func ParseDump

func ParseDump(buf []byte) (*Conf, error)

ParseDump parses a given WireGuard dump and produces a Conf struct.

func (*Conf) Bytes

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

Bytes renders a WireGuard configuration to bytes.

func (*Conf) Equal

func (c *Conf) Equal(b *Conf) bool

Equal checks if two WireGuard configurations are equivalent.

type DNSOrIP

type DNSOrIP struct {
	DNS string
	IP  net.IP

DNSOrIP represents either a DNS name or an IP address. IPs, as they are more specific, are preferred.

func (DNSOrIP) String

func (d DNSOrIP) String() string

String prints the string representation of the struct.

type Endpoint

type Endpoint struct {
	Port uint32

Endpoint represents an `endpoint` key of a `peer` section.

func (*Endpoint) Equal

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

Equal compares two endpoints.

func (*Endpoint) String

func (e *Endpoint) String() string

String prints the string representation of the endpoint.

type Interface

type Interface struct {
	ListenPort uint32
	PrivateKey []byte

Interface represents the `interface` section of a WireGuard configuration.

type Peer

type Peer struct {
	AllowedIPs          []*net.IPNet
	Endpoint            *Endpoint
	PersistentKeepalive int
	PresharedKey        []byte
	PublicKey           []byte
	// The following fields are part of the runtime information, not the configuration.
	LatestHandshake time.Time

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
t or T : Toggle theme light dark auto
y or Y : Canonical URL