wgcfg

package
v1.38.4 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2023 License: BSD-3-Clause Imports: 17 Imported by: 19

Documentation

Overview

Package wgcfg has types and a parser for representing WireGuard config.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewDevice added in v1.18.0

func NewDevice(tunDev tun.Device, bind conn.Bind, logger *device.Logger) *device.Device

NewDevice returns a wireguard-go Device configured for Tailscale use.

func ReconfigDevice

func ReconfigDevice(d *device.Device, cfg *Config, logf logger.Logf) (err error)

ReconfigDevice replaces the existing device configuration with cfg.

Types

type Config

type Config struct {
	Name       string
	NodeID     tailcfg.StableNodeID
	PrivateKey key.NodePrivate
	Addresses  []netip.Prefix
	MTU        uint16
	DNS        []netip.Addr
	Peers      []Peer

	// NetworkLogging enables network logging.
	// It is disabled if either ID is the zero value.
	NetworkLogging struct {
		NodeID   logid.PrivateID
		DomainID logid.PrivateID
	}
}

Config is a WireGuard configuration. It only supports the set of things Tailscale uses.

func DeviceConfig

func DeviceConfig(d *device.Device) (*Config, error)

func FromUAPI

func FromUAPI(r io.Reader) (*Config, error)

FromUAPI generates a Config from r. r should be generated by calling device.IpcGetOperation; it is not compatible with other uapi streams.

func (*Config) Clone added in v1.10.0

func (src *Config) Clone() *Config

Clone makes a deep copy of Config. The result aliases no memory with the original.

func (Config) PeerWithKey

func (config Config) PeerWithKey(k key.NodePublic) (Peer, bool)

PeerWithKey returns the Peer with key k and reports whether it was found.

func (*Config) ToUAPI

func (cfg *Config) ToUAPI(logf logger.Logf, w io.Writer, prev *Config) error

ToUAPI writes cfg in UAPI format to w. Prev is the previous device Config.

Prev is required so that we can remove now-defunct peers without having to remove and re-add all peers, and so that we can avoid writing information about peers that have not changed since the previous time we wrote our Config.

type ParseError

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

func (*ParseError) Error

func (e *ParseError) Error() string

type Peer

type Peer struct {
	PublicKey           key.NodePublic
	DiscoKey            key.DiscoPublic // present only so we can handle restarts within wgengine, not passed to WireGuard
	AllowedIPs          []netip.Prefix
	PersistentKeepalive uint16
	// wireguard-go's endpoint for this peer. It should always equal Peer.PublicKey.
	// We represent it explicitly so that we can detect if they diverge and recover.
	// There is no need to set WGEndpoint explicitly when constructing a Peer by hand.
	// It is only populated when reading Peers from wireguard-go.
	WGEndpoint key.NodePublic
}

func (*Peer) Clone added in v1.10.0

func (src *Peer) Clone() *Peer

Clone makes a deep copy of Peer. The result aliases no memory with the original.

Directories

Path Synopsis
Package nmcfg converts a controlclient.NetMap into a wgcfg config.
Package nmcfg converts a controlclient.NetMap into a wgcfg config.

Jump to

Keyboard shortcuts

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