wgquick

package module
v0.1.3-0...-b61435c Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2019 License: MIT Imports: 16 Imported by: 0

README

wg-quick-go

Build Status GoDoc Go Report Card

wg-quick like library in go for embedding

Roadmap

  • full wg-quick feature parity
    • PreUp
    • PostUp
    • PreDown
    • PostDown
    • DNS
    • MTU
    • Save --> Use MarshallText interface to save config
  • Sync
  • Up
  • Down
  • MarshallText
  • UnmarshallText
  • Minimal test
  • Integration tests ((TODO; have some virtual machines/kvm and wreck havoc :) ))

Caveats

  • Endpoints DNS MarshallText is unsupported
  • Pre/Post Up/Down doesn't support escaped %i, that is all %i are expanded to interface name.
  • SaveConfig in config is only a placeholder (( since there's no reading/writing from files )). Use Unmarshall/Marshall Text to save/load config (( you're responsible for IO)).

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Down

func Down(cfg *Config, iface string, logger *zap.Logger) error

Down destroys the wg interface. Mostly equivalent to `wg-quick down iface`

func ParseKey

func ParseKey(key string) (wgtypes.Key, error)

ParseKey parses the base64 encoded wireguard private key

func Sync

func Sync(cfg *Config, iface string, logger *zap.Logger) error

Sync the config to the current setup for given interface It perform 4 operations: * SyncLink --> makes sure link is up and type wireguard * SyncWireguardDevice --> configures allowedIP & other wireguard specific settings * SyncAddress --> synces linux addresses bounded to this interface * SyncRoutes --> synces all allowedIP routes to route to this interface

func SyncAddress

func SyncAddress(cfg *Config, link netlink.Link, log *zap.Logger) error

SyncAddress adds/deletes all lind assigned IPV4 addressed as specified in the config

func SyncLink(cfg *Config, iface string, log *zap.Logger) (netlink.Link, error)

SyncLink synces link state with the config. It does not sync Wireguard settings, just makes sure the device is up and type wireguard

func SyncRoutes

func SyncRoutes(cfg *Config, link netlink.Link, managedRoutes []net.IPNet, logger *zap.Logger) error

SyncRoutes adds/deletes all route assigned IPV4 addressed as specified in the config

func SyncWireguardDevice

func SyncWireguardDevice(cfg *Config, link netlink.Link, log *zap.Logger) error

SyncWireguardDevice synces wireguard vpn setting on the given link. It does not set routes/addresses beyond wg internal crypto-key routing, only handles wireguard specific settings

func Up

func Up(cfg *Config, iface string, logger *zap.Logger) error

Up sets and configures the wg interface. Mostly equivalent to `wg-quick up iface`

Types

type Config

type Config struct {
	wgtypes.Config

	// Address list of IP (v4 or v6) addresses (optionally with CIDR masks) to be assigned to the interface. May be specified multiple times.
	Address []net.IPNet

	// list of IP (v4 or v6) addresses to be set as the interface’s DNS servers. May be specified multiple times. Upon bringing the interface up, this runs ‘resolvconf -a tun.INTERFACE -m 0 -x‘ and upon bringing it down, this runs ‘resolvconf -d tun.INTERFACE‘. If these particular invocations of resolvconf(8) are undesirable, the PostUp and PostDown keys below may be used instead.
	DNS []net.IP

	// MTU is automatically determined from the endpoint addresses or the system default route, which is usually a sane choice. However, to manually specify an MTU to override this automatic discovery, this value may be specified explicitly.
	MTU int

	// Table — Controls the routing table to which routes are added.
	Table int

	// PreUp, PostUp, PreDown, PostDown — script snippets which will be executed by bash(1) before/after setting up/tearing down the interface, most commonly used to configure custom DNS options or firewall rules. The special string ‘%i’ is expanded to INTERFACE. Each one may be specified multiple times, in which case the commands are executed in order.
	PreUp    string
	PostUp   string
	PreDown  string
	PostDown string

	// RouteProtocol to set on the route. See linux/rtnetlink.h  Use value > 4 or default 0
	RouteProtocol int

	// RouteMetric sets this metric on all managed routes. Lower number means pick this one
	RouteMetric int

	// Address label to set on the link
	AddressLabel string

	// SaveConfig — if set to ‘true’, the configuration is saved from the current state of the interface upon shutdown.
	// Currently unsupported
	SaveConfig bool
}

Config represents full wg-quick like config structure

func (*Config) MarshalText

func (cfg *Config) MarshalText() (text []byte, err error)

func (*Config) String

func (cfg *Config) String() string

func (*Config) UnmarshalText

func (cfg *Config) UnmarshalText(text []byte) error

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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