operator

package module
v0.0.0-...-80b16a5 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2023 License: MIT Imports: 15 Imported by: 0

README

Wireguard Operator

A simple operator that exposes Wireguard configuration through HTTP JSON, supports adding, removing and replacing peers with automatic IP allocation.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrPeerNotFound = errors.New("peer not found")

ErrPeerNotFound is returned when unable to find a matching peer while looking up information about it.

Functions

func IDHandler

func IDHandler(wgID WgIdentity) http.HandlerFunc

func PeerHandler

func PeerHandler(c WgDeviceConfigurator, wgID WgIdentity, p IPPool, ip6prefix *net.IPNet) http.HandlerFunc

Types

type IPPool

type IPPool interface {
	Allocate() (net.IP, error)
	Free(net.IP) error
	Remove(...net.IP) error
}

IPPool knows how to allocate IPs and free previously allocated ones.

type Pool

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

Pool is a pool of available IP numbers for allocation.

func NewPool

func NewPool(cidr string) (*Pool, error)

NewPool creates a new pool with a CIDR.

func (*Pool) Allocate

func (p *Pool) Allocate() (ip net.IP, err error)

Allocate assigns a new IP to the pool for use.

func (*Pool) Free

func (p *Pool) Free(ip net.IP) error

Free returns the IP to the pool to be used by other allocations.

func (*Pool) Remove

func (p *Pool) Remove(ips ...net.IP) error

Remove selected IPs from the available pool.

type WgClient

type WgClient struct {
	*wgctrl.Client
	// contains filtered or unexported fields
}

WgClient is a thin wrapper around wgctrl for binding config to a specific interface link.

func NewWgClient

func NewWgClient(link *WgLink, port int, pk string) (*WgClient, error)

func (*WgClient) ConfigureDevice

func (c *WgClient) ConfigureDevice(cfg wgtypes.Config) error

func (*WgClient) Peers

func (c *WgClient) Peers() ([]wgtypes.Peer, error)

func (*WgClient) PublicKey

func (c *WgClient) PublicKey() []byte

func (*WgClient) ResolvePeerNets

func (c *WgClient) ResolvePeerNets(key wgtypes.Key) ([]net.IPNet, error)

type WgDeviceConfigurator

type WgDeviceConfigurator interface {
	ConfigureDevice(wgtypes.Config) error
	ResolvePeerNets(wgtypes.Key) ([]net.IPNet, error)
	Peers() ([]wgtypes.Peer, error)
}

WgDeviceConfigurator configures one WireGuard interface and tracks IPs of registered peers.

type WgIdentity

type WgIdentity interface {
	PublicKey() []byte
	Port() int
}

WgIdentity is the information required for a remote peer to connect via WireGuard.

type WgLink struct {
	*netlink.LinkAttrs
}
func NewWgLink(ifName string) (*WgLink, error)

Use existing link or create a new one.

func (*WgLink) AddrAdd

func (wg *WgLink) AddrAdd(addrs ...*netlink.Addr) error

func (*WgLink) Attrs

func (wg *WgLink) Attrs() *netlink.LinkAttrs

func (*WgLink) Close

func (wg *WgLink) Close() error

func (WgLink) Type

func (WgLink) Type() string

Directories

Path Synopsis
cmd
wgo

Jump to

Keyboard shortcuts

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