wireguard

package
v0.0.0-...-637acb3 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2025 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultMTU                 = 1420
	DefaultPersistentKeepalive = 16
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ControllerManager

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

func NewControllerManager

func NewControllerManager(cfg *config.Config) (*ControllerManager, error)

func (*ControllerManager) GetAllControllers

func (c *ControllerManager) GetAllControllers() []backendInstance

func (*ControllerManager) GetController

func (*ControllerManager) GetControllerByName

func (c *ControllerManager) GetControllerByName(backend domain.InterfaceBackend) domain.InterfaceController

func (*ControllerManager) GetControllerNames

func (c *ControllerManager) GetControllerNames() []config.BackendBase

type EventBus

type EventBus interface {
	// Publish sends a message to the message bus.
	Publish(topic string, args ...any)
	// Subscribe subscribes to a topic
	Subscribe(topic string, fn interface{}) error
}

type InterfaceAndPeerDatabaseRepo

type InterfaceAndPeerDatabaseRepo interface {
	GetInterface(ctx context.Context, id domain.InterfaceIdentifier) (*domain.Interface, error)
	GetInterfaceAndPeers(ctx context.Context, id domain.InterfaceIdentifier) (*domain.Interface, []domain.Peer, error)
	GetPeersStats(ctx context.Context, ids ...domain.PeerIdentifier) ([]domain.PeerStatus, error)
	GetAllInterfaces(ctx context.Context) ([]domain.Interface, error)
	GetInterfaceIps(ctx context.Context) (map[domain.InterfaceIdentifier][]domain.Cidr, error)
	SaveInterface(
		ctx context.Context,
		id domain.InterfaceIdentifier,
		updateFunc func(in *domain.Interface) (*domain.Interface, error),
	) error
	DeleteInterface(ctx context.Context, id domain.InterfaceIdentifier) error
	GetInterfacePeers(ctx context.Context, id domain.InterfaceIdentifier) ([]domain.Peer, error)
	GetUserPeers(ctx context.Context, id domain.UserIdentifier) ([]domain.Peer, error)
	SavePeer(
		ctx context.Context,
		id domain.PeerIdentifier,
		updateFunc func(in *domain.Peer) (*domain.Peer, error),
	) error
	DeletePeer(ctx context.Context, id domain.PeerIdentifier) error
	GetPeer(ctx context.Context, id domain.PeerIdentifier) (*domain.Peer, error)
	GetUsedIpsPerSubnet(ctx context.Context, subnets []domain.Cidr) (map[domain.Cidr][]domain.Cidr, error)
}

type Manager

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

func NewWireGuardManager

func NewWireGuardManager(
	cfg *config.Config,
	bus EventBus,
	wg *ControllerManager,
	db InterfaceAndPeerDatabaseRepo,
) (*Manager, error)

func (Manager) ApplyPeerDefaults

func (m Manager) ApplyPeerDefaults(ctx context.Context, in *domain.Interface) error

ApplyPeerDefaults applies the interface defaults to all peers of the given interface.

func (Manager) BootstrapInterfacesFromConfig

func (m Manager) BootstrapInterfacesFromConfig(ctx context.Context) (bool, error)

BootstrapInterfacesFromConfig seeds the database with interfaces from config.Provisioning only if the database currently contains no interfaces.

It never applies changes to the host network stack; applying is handled by RestoreInterfaceState.

func (Manager) CreateDefaultPeer

func (m Manager) CreateDefaultPeer(ctx context.Context, userId domain.UserIdentifier) error

CreateDefaultPeer creates a default peer for the given user on all server interfaces.

func (Manager) CreateInterface

func (m Manager) CreateInterface(ctx context.Context, in *domain.Interface) (*domain.Interface, error)

CreateInterface creates a new interface with the given configuration.

func (Manager) CreateMultiplePeers

func (m Manager) CreateMultiplePeers(
	ctx context.Context,
	interfaceId domain.InterfaceIdentifier,
	r *domain.PeerCreationRequest,
) ([]domain.Peer, error)

CreateMultiplePeers creates multiple new peers for the given user identifiers. It calls PreparePeer for each user identifier in the request.

func (Manager) CreatePeer

func (m Manager) CreatePeer(ctx context.Context, peer *domain.Peer) (*domain.Peer, error)

CreatePeer creates a new peer.

func (Manager) CreateUserPeerOnInterface

func (m Manager) CreateUserPeerOnInterface(
	ctx context.Context,
	userId domain.UserIdentifier,
	interfaceId domain.InterfaceIdentifier,
) (*domain.Peer, error)

CreateUserPeerOnInterface creates a new peer for the given user on the given interface. Peer settings are derived from the interface defaults. The user is not allowed to override any settings.

func (Manager) DeleteInterface

func (m Manager) DeleteInterface(ctx context.Context, id domain.InterfaceIdentifier) error

DeleteInterface deletes the given interface.

func (Manager) DeletePeer

func (m Manager) DeletePeer(ctx context.Context, id domain.PeerIdentifier) error

DeletePeer deletes the peer with the given identifier.

func (Manager) GetAllInterfaces

func (m Manager) GetAllInterfaces(ctx context.Context) ([]domain.Interface, error)

GetAllInterfaces returns all interfaces that are available in the database.

func (Manager) GetAllInterfacesAndPeers

func (m Manager) GetAllInterfacesAndPeers(ctx context.Context) ([]domain.Interface, [][]domain.Peer, error)

GetAllInterfacesAndPeers returns all interfaces and their peers.

func (Manager) GetInterfaceAndPeers

func (m Manager) GetInterfaceAndPeers(ctx context.Context, id domain.InterfaceIdentifier) (
	*domain.Interface,
	[]domain.Peer,
	error,
)

GetInterfaceAndPeers returns the interface and all peers for the given interface identifier.

func (Manager) GetPeer

func (m Manager) GetPeer(ctx context.Context, id domain.PeerIdentifier) (*domain.Peer, error)

GetPeer returns the peer with the given identifier.

func (Manager) GetPeerInterfaces

func (m Manager) GetPeerInterfaces(ctx context.Context, userId domain.UserIdentifier) ([]domain.Interface, error)

GetPeerInterfaces returns the list of interfaces a normal user is allowed to select when creating a new peer via self-service.

func (Manager) GetPeerStats

func (m Manager) GetPeerStats(ctx context.Context, id domain.InterfaceIdentifier) ([]domain.PeerStatus, error)

GetPeerStats returns the status of the peer with the given identifier.

func (Manager) GetUserInterfaces

func (m Manager) GetUserInterfaces(ctx context.Context, _ domain.UserIdentifier) ([]domain.Interface, error)

GetUserInterfaces is deprecated. Self-provisioning was removed.

func (Manager) GetUserPeerStats

func (m Manager) GetUserPeerStats(ctx context.Context, id domain.UserIdentifier) ([]domain.PeerStatus, error)

GetUserPeerStats returns the status of all peers for the given user.

func (Manager) GetUserPeers

func (m Manager) GetUserPeers(ctx context.Context, id domain.UserIdentifier) ([]domain.Peer, error)

GetUserPeers returns all peers for the given user.

func (Manager) ImportNewInterfaces

func (m Manager) ImportNewInterfaces(ctx context.Context, filter ...domain.InterfaceIdentifier) (int, error)

ImportNewInterfaces imports all new physical interfaces that are available on the system. If a filter is set, only interfaces that match the filter will be imported.

func (Manager) PrepareInterface

func (m Manager) PrepareInterface(ctx context.Context) (*domain.Interface, error)

PrepareInterface generates a new interface with fresh keys, ip addresses and a listen port.

func (Manager) PreparePeer

func (m Manager) PreparePeer(ctx context.Context, id domain.InterfaceIdentifier) (*domain.Peer, error)

PreparePeer prepares a new peer for the given interface with fresh keys and ip addresses.

func (Manager) RestoreInterfaceState

func (m Manager) RestoreInterfaceState(
	ctx context.Context,
	updateDbOnError bool,
	filter ...domain.InterfaceIdentifier,
) error

RestoreInterfaceState restores the state of all physical interfaces and their peers. The final state of the interfaces and peers will be the same as stored in the database.

func (Manager) StartBackgroundJobs

func (m Manager) StartBackgroundJobs(ctx context.Context)

StartBackgroundJobs starts background jobs like the expired peers check. This method is non-blocking.

func (Manager) UpdateInterface

func (m Manager) UpdateInterface(ctx context.Context, in *domain.Interface) (*domain.Interface, []domain.Peer, error)

UpdateInterface updates the given interface with the new configuration.

func (Manager) UpdatePeer

func (m Manager) UpdatePeer(ctx context.Context, peer *domain.Peer) (*domain.Peer, error)

UpdatePeer updates the given peer.

type StatisticsCollector

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

func NewStatisticsCollector

NewStatisticsCollector creates a new statistics collector.

func (*StatisticsCollector) StartBackgroundJobs

func (c *StatisticsCollector) StartBackgroundJobs(ctx context.Context)

StartBackgroundJobs starts the background jobs for the statistics collector. This method is non-blocking and returns immediately.

type StatisticsDatabaseRepo

type StatisticsDatabaseRepo interface {
	GetAllInterfaces(ctx context.Context) ([]domain.Interface, error)
	GetInterfacePeers(ctx context.Context, id domain.InterfaceIdentifier) ([]domain.Peer, error)
	GetPeer(ctx context.Context, id domain.PeerIdentifier) (*domain.Peer, error)
	UpdatePeerStatus(
		ctx context.Context,
		id domain.PeerIdentifier,
		updateFunc func(in *domain.PeerStatus) (*domain.PeerStatus, error),
	) error
	UpdateInterfaceStatus(
		ctx context.Context,
		id domain.InterfaceIdentifier,
		updateFunc func(in *domain.InterfaceStatus) (*domain.InterfaceStatus, error),
	) error
	DeletePeerStatus(ctx context.Context, id domain.PeerIdentifier) error
}

type StatisticsEventBus

type StatisticsEventBus interface {
	// Subscribe subscribes to a topic
	Subscribe(topic string, fn interface{}) error
	// Publish sends a message to the message bus.
	Publish(topic string, args ...any)
}

type StatisticsMetricsServer

type StatisticsMetricsServer interface {
	UpdateInterfaceMetrics(status domain.InterfaceStatus)
	UpdatePeerMetrics(peer *domain.Peer, status domain.PeerStatus)
}

type WgQuickController

type WgQuickController interface {
	ExecuteInterfaceHook(ctx context.Context, id domain.InterfaceIdentifier, hookCmd string) error
	SetDNS(ctx context.Context, id domain.InterfaceIdentifier, dnsStr, dnsSearchStr string) error
	UnsetDNS(ctx context.Context, id domain.InterfaceIdentifier, dnsStr, dnsSearchStr string) error
}

Jump to

Keyboard shortcuts

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