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
- Variables
- type Client
- func (c *Client) Close() error
- func (c *Client) SetDevice(ifname string, priv [32]byte, port uint16, o awgcfg.Obfuscation, ...) error
- func (c *Client) SetPeers(ifname string, replaceAll bool, peers []awgcfg.Peer) error
- func (c *Client) Stats(ifname string) ([]awgcfg.PeerStat, error)
- func (c *Client) WatchUnknownPeers(fn func(ifname string)) (stop func(), err error)
- type Info
Constants ¶
const (
// SetPeers batches: one nested attribute is limited to 64 KiB (1000 peers at once fails in the encoder).
MaxPeersPerMessage = 250
)
Variables ¶
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 ¶
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) 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 ¶
SetPeers changes peers only (batches of at most MaxPeersPerMessage; the caller batches).
func (*Client) Stats ¶
Stats dumps the device (NLM_F_DUMP; the peers of one device may arrive in several messages). The dump carries the interface's private key and the header protection key in clear: nothing here decodes or keeps them.
func (*Client) WatchUnknownPeers ¶
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).