lib

package
v0.0.0-...-c9180d9 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AsciiPeerConfig

func AsciiPeerConfig(peer Peer, peerType string, server Server) (*bytes.Buffer, error)

func GetWGPeerTemplate

func GetWGPeerTemplate(peer Peer, peerType PeerType, server Server) (*bytes.Buffer, error)

GetWGPeerTemplate returns a template string to be used when configuring a peer

Types

type JSONIPNet

type JSONIPNet struct {
	IPNet net.IPNet
}

func (JSONIPNet) MarshalJSON

func (n JSONIPNet) MarshalJSON() ([]byte, error)

func (*JSONIPNet) String

func (n *JSONIPNet) String() string

func (*JSONIPNet) UnmarshalJSON

func (n *JSONIPNet) UnmarshalJSON(b []byte) error

type JSONKey

type JSONKey struct {
	Key wgtypes.Key
}

func GenerateJSONKey

func GenerateJSONKey() (JSONKey, error)

func GenerateJSONPrivateKey

func GenerateJSONPrivateKey() (JSONKey, error)

func (JSONKey) MarshalJSON

func (k JSONKey) MarshalJSON() ([]byte, error)

func (JSONKey) PublicKey

func (k JSONKey) PublicKey() JSONKey

func (*JSONKey) UnmarshalJSON

func (k *JSONKey) UnmarshalJSON(b []byte) error

type Peer

type Peer struct {
	Hostname            string
	Owner               string
	Description         string
	IP                  net.IP
	IP6                 net.IP
	Added               time.Time
	PublicKey           JSONKey
	PrivateKey          JSONKey
	PresharedKey        JSONKey
	Networks            []JSONIPNet
	PersistentKeepalive int
}

func NewPeer

func NewPeer(server *Server, owner string, hostname string, description string) (Peer, error)

type PeerType

type PeerType int

PeerType is what configuration to use when generating peer config files

const (
	// WGQuick is used by wg-quick to set up a peer
	// https://manpages.debian.org/unstable/wireguard-tools/wg-quick.8.en.html
	WGQuick PeerType = iota
	// Vyatta is used by Ubiquiti routers
	// https://github.com/WireGuard/wireguard-vyatta-ubnt/
	Vyatta
	// NixOS is a declartive linux distro
	// https://nixos.wiki/wiki/Wireguard
	NixOS
)

type Server

type Server struct {
	ExternalHostname    string
	ExternalIP          net.IP
	ExternalIP6         net.IP
	ListenPort          int
	Domain              string
	InterfaceName       string
	Network             JSONIPNet
	Network6            JSONIPNet
	IP                  net.IP
	IP6                 net.IP
	DNS                 net.IP
	PrivateKey          JSONKey
	PostUp              string
	PostDown            string
	FallbackWGBin       string
	Peers               []Peer
	Networks            []JSONIPNet
	PersistentKeepalive int
}

func (*Server) AllocateIP

func (s *Server) AllocateIP() (net.IP, error)

AllocateIP finds a free IPv4 for a new Peer (sequential allocation)

func (*Server) AllocateIP6

func (s *Server) AllocateIP6() (net.IP, error)

AllocateIP6 finds a free IPv6 for a new Peer (pseudorandom allocation)

func (*Server) ConfigureDevice

func (s *Server) ConfigureDevice() error

ConfigureDevice sets up the WG interface

func (s *Server) CreateLink() error

CreateLink sets up the WG interface and link with the correct address

func (s *Server) DeleteLink() error

DeleteLink removes the Netlink interface

func (*Server) GetPeers

func (s *Server) GetPeers() []wgtypes.PeerConfig

func (*Server) IPAllocated

func (s *Server) IPAllocated(IP net.IP) bool

IPAllocated checks the existing used ips and returns bool depending on if the IP is in use

func (*Server) Up

func (s *Server) Up() error

Jump to

Keyboard shortcuts

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