wgcfg

package
v1.14.6 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2021 License: BSD-3-Clause Imports: 15 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 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
	PrivateKey wgkey.Private
	Addresses  []netaddr.IPPrefix
	MTU        uint16
	DNS        []netaddr.IP
	Peers      []Peer
}

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 wgkey.Key) (Peer, bool)

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

func (*Config) ToUAPI

func (cfg *Config) ToUAPI(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.

type Endpoints added in v1.10.0

type Endpoints struct {
	// PublicKey is the public key for the remote node.
	PublicKey wgkey.Key `json:"pk"`
	// DiscoKey is the disco key associated with the remote node.
	DiscoKey tailcfg.DiscoKey `json:"dk,omitempty"`
	// IPPorts is a set of possible ip+ports the remote node can be reached at.
	// This is used only for legacy connections to pre-disco (pre-0.100) peers.
	IPPorts IPPortSet `json:"ipp,omitempty"`
}

Endpoints represents the routes to reach a remote node. It is serialized and provided to wireguard-go as a conn.Endpoint.

func (*Endpoints) Clone added in v1.10.0

func (src *Endpoints) Clone() *Endpoints

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

func (Endpoints) Equal added in v1.10.0

func (e Endpoints) Equal(f Endpoints) bool

type IPPortSet added in v1.10.0

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

IPPortSet is an immutable slice of netaddr.IPPorts.

func NewIPPortSet added in v1.10.0

func NewIPPortSet(ipps ...netaddr.IPPort) IPPortSet

NewIPPortSet returns an IPPortSet containing the ports in ipp.

func (*IPPortSet) Clone added in v1.10.0

func (src *IPPortSet) Clone() *IPPortSet

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

func (IPPortSet) EqualUnordered added in v1.10.0

func (s IPPortSet) EqualUnordered(t IPPortSet) bool

EqualUnordered reports whether s and t contain the same IPPorts, regardless of order.

func (IPPortSet) IPPorts added in v1.10.0

func (s IPPortSet) IPPorts() []netaddr.IPPort

IPPorts returns a slice of netaddr.IPPorts containing the IPPorts in s.

func (IPPortSet) MarshalJSON added in v1.10.0

func (s IPPortSet) MarshalJSON() ([]byte, error)

MarshalJSON marshals s into JSON. It is necessary so that IPPortSet's fields can be unexported, to guarantee immutability.

func (IPPortSet) String added in v1.10.0

func (s IPPortSet) String() string

String returns a comma-separated list of all IPPorts in s.

func (*IPPortSet) UnmarshalJSON added in v1.10.0

func (s *IPPortSet) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals s from JSON. It is necessary so that IPPortSet's fields can be unexported, to guarantee immutability.

type ParseError

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

func (*ParseError) Error

func (e *ParseError) Error() string

type Peer

type Peer struct {
	PublicKey           wgkey.Key
	AllowedIPs          []netaddr.IPPrefix
	Endpoints           Endpoints
	PersistentKeepalive uint16
}

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