wg

package
v0.3.9 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2021 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IPPool

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

IPPool allows to generate IPv6 address from a /64 subnet

func NewIPPool

func NewIPPool(kp identity.KeyPair) *IPPool

NewIPPool creates a IP pool allocator

func (*IPPool) Gateway

func (p *IPPool) Gateway() *net.IPNet

Gateway returns the Gateway address of the subnet managed by the pool

func (*IPPool) Get

func (p *IPPool) Get(id []byte) (net.IP, error)

Get generates a IP that is part of the subnet of the pool by hashing the seed of the pool and and ID. the hash is then used to generated the last 8 byte of the ipv6 address

func (*IPPool) Subnet

func (p *IPPool) Subnet() net.IPNet

Subnet generates a /64 IPv6 prefix by hashing the seed then using the hash value to generate IP the idea is the same seed always generate the same prefix

type Mgr

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

Mgr is manager of the Gateway4To6

func New

func New(kp identity.KeyPair, ipAlloc *IPPool, endpoint string, wgIface string) (*Mgr, error)

New creates a wireguard manager

func (*Mgr) AddPeer

func (m *Mgr) AddPeer(user, pubKey string) (PeerConfig, error)

AddPeer addd a peer identified by pubkey to the wireguard network The peer address is allocated from the manager pool and returned to the caller

func (*Mgr) Close

func (m *Mgr) Close() error

Close removes the network namespace and wireguard interface

func (*Mgr) RemovePeer

func (m *Mgr) RemovePeer(pubKey string) error

RemovePeer removes a peer identified by pubkey from the wireguard network

type Peer

type Peer struct {
	PublicKey  string   `json:"public_key"`
	Endpoint   string   `json:"endpoint"`
	AllowedIPs []string `json:"allowed_ips"`
}

Peer is a wireguard peer

type PeerConfig

type PeerConfig struct {
	IPs   []string `json:"ips"`
	Peers []Peer   `json:"peers"`
}

PeerConfig is the wireguard configuration elements returns to the user he can use it to create its wg config

Jump to

Keyboard shortcuts

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