wireguard

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2023 License: MPL-2.0 Imports: 22 Imported by: 3

Documentation

Overview

Package wireguard manages kernel and user-space Wireguard interfaces.

Index

Constants

View Source
const (
	// PeerDownInterval is the time since last handshake when established peer is considered to be down.
	//
	// WG whitepaper defines a downed peer as being:
	// Handshake Timeout (180s) + Rekey Timeout (5s) + Rekey Attempt Timeout (90s)
	//
	// This interval is applied when the link is already established.
	PeerDownInterval = (180 + 5 + 90) * time.Second

	// LinkMTU is the suggested MTU of the link for Wireguard.
	//
	// Wireguard sets DF (Don't Fragment) bit on all packets, so the MTU of the link
	// should be so that with the overhead of the Wireguard header, the packet
	// is still smaller than the MTU of the link.
	//
	// To be on the safe side, we set the MTU to 1280, which is the minimum MTU
	// for IPv6.
	LinkMTU = 1280

	// RecommendedPersistentKeepAliveInterval is the recommended interval for persistent keepalive.
	RecommendedPersistentKeepAliveInterval = 25 * time.Second
)

Variables

This section is empty.

Functions

func NetworkPrefix

func NetworkPrefix(installationID string) netip.Prefix

NetworkPrefix returns IPv6 prefix for the SideroLink.

Server is using the first address in the block. Nodes are using random addresses from the /64 space.

func UAPIOpen

func UAPIOpen(interfaceName string) (net.Listener, error)

UAPIOpen opens a UAPI socket.

Types

type Device

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

Device manages Wireguard link.

func NewDevice

func NewDevice(address netip.Prefix, privateKey wgtypes.Key, listenPort uint16,
	forceUserspace bool, logger *zap.Logger,
) (*Device, error)

NewDevice creates a new device with settings.

func (*Device) Close

func (dev *Device) Close() error

Close the device.

func (*Device) Peers

func (dev *Device) Peers() ([]wgtypes.Peer, error)

Peers returns underlying peer states from the underlying wireguard device.

func (*Device) Run

func (dev *Device) Run(ctx context.Context, logger *zap.Logger, peers PeerSource) error

Run the device.

type PeerEvent

type PeerEvent struct {
	PubKey wgtypes.Key

	Remove   bool
	Endpoint string

	Address netip.Addr

	PersistentKeepAliveInterval *time.Duration
}

PeerEvent is the event about peer state change.

type PeerSource

type PeerSource interface {
	EventCh() <-chan PeerEvent
}

PeerSource is the interface of the "database" providing SideroLink peer information.

Jump to

Keyboard shortcuts

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