awgnl

package
v0.2.0-dev.12 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package awgnl talks to the amneziawg kernel module over generic netlink (family "amneziawg", WG_GENL_VERSION 3, the AWG 3.0/3.1 encoding). It is our own client because the only fork of wgctrl that knows AWG (awgctrl-go) refuses genl version 3. Attribute numbers and types follow the AmneziaWG kernel module's netlink API and were checked against a real module (v3.1.20260906).

The package builds on every OS (netlink itself only works on Linux): constants are local instead of golang.org/x/sys/unix so the encoder is testable byte for byte everywhere.

Index

Constants

View Source
const (

	// SetPeers batches: one nested attribute is limited to 64 KiB (1000 peers at once fails in the encoder).
	MaxPeersPerMessage = 250
)

Variables

View Source
var ErrNoModule = errors.New("awgnl: the amneziawg kernel module is not loaded")

ErrNoModule means the generic netlink family does not exist: the module is not loaded.

Functions

This section is empty.

Types

type Client

type Client struct {
	Info Info
	// contains filtered or unexported fields
}

Client is a connection to the module. Methods are serialised by the caller (the engine holds its own lock).

func Dial

func Dial() (*Client, error)

Dial opens the connection and asks for the family. ErrNoModule when the family is absent, an error when its genl version is not 3 (only that encoding is implemented).

func (*Client) Close

func (c *Client) Close() error

Close closes the connection.

func (*Client) SetDevice

func (c *Client) SetDevice(ifname string, priv [32]byte, port uint16, o awgcfg.Obfuscation, peers []awgcfg.Peer) error

SetDevice sends key, port and ALL obfuscation attributes in one message; the module validates the final state. It is not atomic: on EINVAL part of the attributes is already applied, so the caller deletes the interface and starts over. Changing obfuscation on a live interface drops every session, which is why the engine recreates it. The reason for an EINVAL is only in the kernel log (dynamic debug), hence the validator.

func (*Client) SetPeers

func (c *Client) SetPeers(ifname string, replaceAll bool, peers []awgcfg.Peer) error

SetPeers changes peers only (batches of at most MaxPeersPerMessage; the caller batches).

func (*Client) Stats

func (c *Client) Stats(ifname string) ([]awgcfg.PeerStat, error)

Stats dumps the device (NLM_F_DUMP; the peers of one device may arrive in several messages, and one peer may be cut between two of them: it is returned once, with all its allowed ips). The dump carries the interface's private key and the header protection key in clear: nothing here decodes or keeps them.

func (*Client) WatchUnknownPeers

func (c *Client) WatchUnknownPeers(fn func(ifname string)) (stop func(), err error)

WatchUnknownPeers joins the multicast group "auth" on a connection of its own and calls fn(ifname) for every WG_CMD_UNKNOWN_PEER: a valid handshake initiation from a key the interface does not know, which tells "old key on the client" from "parameters differ". Not exercised against a real module: best effort, the caller ignores an error. The returned stop function ends the goroutine.

type Info

type Info struct {
	ID          uint16
	GenlVersion uint8  // 2 = AWG 1.x/2.0 encoding, 3 = AWG 3.x
	MaxAttr     uint32 // 32 = 3.0, 34 = 3.1
}

Info is what the module says about itself. Use it for capability detection, not /sys/module/amneziawg/version (it reads 3.1.20260812 on every 3.1 build and 1.0.0 on `make` builds).

func (Info) Is31

func (i Info) Is31() bool

Is31 reports whether the module knows RandomTrailers and DisableCookies.

Jump to

Keyboard shortcuts

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