wgtunnel

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddClientHandler

func AddClientHandler(st Store, smdClient smdclient.SMDClientInterface) http.HandlerFunc

addClientHandler handles adding a WireGuard client.

func AddWireGuardPeer

func AddWireGuardPeer(interfaceID, publicKey, vpnIP, clientIP string) error

AddWireGuardPeer adds a peer to the WireGuard configuration.

func GetUsableIP

func GetUsableIP(network *net.IPNet) (net.IP, error)

GetUsableIP checks if the given IP in a net.IPNet is usable. If not, it returns the first usable IP in the subnet.

Types

type IPAllocator

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

IPAllocator manages IP address allocation within a network range.

func NewIPAllocator

func NewIPAllocator(cidr string) (*IPAllocator, error)

NewIPAllocator initializes a new IPAllocator for a given network.

func (*IPAllocator) IsAllocated

func (a *IPAllocator) IsAllocated(ipAddr net.IPAddr) bool

IsAllocated checks if an IP address is currently allocated.

func (*IPAllocator) NextAvailable

func (a *IPAllocator) NextAvailable() (net.IPAddr, error)

NextAvailable returns the next available IP address in the range.

func (*IPAllocator) Release

func (a *IPAllocator) Release(ipAddr net.IPAddr) error

Release releases an IP address back to the pool.

func (*IPAllocator) Reserve

func (a *IPAllocator) Reserve(ipAddr net.IPAddr) error

Reserve reserves a specific IP address.

type InterfaceManager

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

func NewInterfaceManager

func NewInterfaceManager(name string, localIp net.IP, network *net.IPNet) *InterfaceManager

func (*InterfaceManager) GetInterfaceName

func (m *InterfaceManager) GetInterfaceName() string

func (*InterfaceManager) GetPeers

func (m *InterfaceManager) GetPeers() map[string]PeerConfig

func (*InterfaceManager) GetServerConfig

func (m *InterfaceManager) GetServerConfig() (ServerConfig, error)

func (*InterfaceManager) IpForPeer

func (m *InterfaceManager) IpForPeer(peerName string, publicKey string) string

IpForPeer allocates an IP address for a given peer based on its name and public key. If the peer already exists, it returns the existing IP address. Otherwise, it allocates a new IP address for the peer and stores the peer configuration.

func (*InterfaceManager) PublicKey

func (m *InterfaceManager) PublicKey() (string, error)

func (*InterfaceManager) RemovePeer

func (m *InterfaceManager) RemovePeer(peerName string) error

func (*InterfaceManager) StartServer

func (m *InterfaceManager) StartServer() error

type PeerConfig

type PeerConfig struct {
	PublicKey string     `json:"public_key"`
	IP        net.IPAddr `json:"ip"`
}

type PublicKeyRequest

type PublicKeyRequest struct {
	PublicKey string `json:"public_key"`
}

PublicKeyRequest represents the JSON payload for a WireGuard public key.

type ServerConfig

type ServerConfig struct {
	PublicKey string `json:"public_key"`
	IP        string `json:"ip"`
	Port      string `json:"port"`
}

type Store

type Store interface {
	IpForPeer(peerName, publicKey string) string
	GetInterfaceName() string
	GetServerConfig() (ServerConfig, error)
}

Jump to

Keyboard shortcuts

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