awg

package
v0.1.63 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: AGPL-3.0 Imports: 29 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 awg is the node's AmneziaWG engine (engine.Engine). One Engine serves every awg inbound of the node; one inbound is one profile = one network interface "mgawg<port>" on its own UDP port (obfuscation is a property of the interface, a peer that speaks other parameters cannot share it). Two backends sit behind awgBackend: the kernel module through our own genetlink client, and amneziawg-go inside the agent process (the default).

Semantics the agent relies on:

  • A peer is a credential. Users-only changes go to the live interface: a new key is added, a changed address or preshared key is an update_only + replace_allowed_ips, a vanished key is removed. An unchanged active peer is never removed and re-added (its client would freeze for ~15 s). The diff is taken against what the device reports, so a peer deleted behind our back comes back with the next Apply.
  • Any change of port, version, server key, obfuscation or tunnel address recreates the interface (Restarted). Only the MTU is changed live.
  • Traffic: per peer, from the device counters; Up = rx_bytes, Down = tx_bytes (the client's view). The previous absolute value is kept per (inbound, public key); a smaller new value means the peer was recreated and the delta is the new value. The final counters of a removed peer are flushed before it goes.
  • The host layer (nftables masquerade, MSS clamp, ip_forward, the UDP counter) belongs to the agent (hostctl.SetTunnels); this engine only builds the interface, its address and MTU.

Index

Constants

View Source
const (
	ReasonBackendUnavailable = "awg_backend_unavailable"
	ReasonModuleTooOld       = "awg_module_too_old"
)

Reasons the engine reports (InboundResult.error / Health detail start with the code).

View Source
const Protocol = "awg"

Protocol is the plugin id this engine serves.

Variables

View Source
var Factory engine.Factory = New

Factory is the engine.Factory with the default (auto) backend choice; FactoryFor takes the setting.

Functions

func FactoryFor

func FactoryFor(backend string) engine.Factory

FactoryFor returns a factory for the given NodeSettings.awg_backend.

func IfaceName

func IfaceName(port uint16) string

IfaceName is the name of the interface an inbound on a UDP port gets: "mgawg51842". The agent derives the same name for the firewall of the tunnel (hostctl.TunnelIface) and its Cleanup deletes links that carry the prefix; a test keeps them equal.

func New

func New(env engine.Env) (engine.Engine, error)

New builds the engine with the auto backend choice.

Types

type BackendStatus

type BackendStatus struct {
	Mode      string // what was asked: auto | kernel | userspace
	Name      string // "kernel" | "userspace"; "" when unavailable
	Version   string
	Available bool
	Reason    string // when unavailable: a short English fact, e.g. "no /dev/net/tun"
}

BackendStatus says which backend the engine runs, or why there is none.

type Engine

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

Engine implements engine.Engine.

func NewWithOptions

func NewWithOptions(env engine.Env, opts Options) (*Engine, error)

NewWithOptions builds the engine and detects the backend. No usable backend is not an error here: every awg inbound then fails with awg_backend_unavailable and BackendStatus says why (a node without AWG keeps its other engines).

func (*Engine) Apply

func (e *Engine) Apply(ctx context.Context, spec plugin.InboundSpec, creds []plugin.UserCred) (engine.ApplyReport, error)

Apply makes the inbound match (spec, creds).

func (*Engine) AwgHealth

func (e *Engine) AwgHealth() []InboundHealth

AwgHealth reports every inbound that has an interface. Calling it resets UnknownPeerEvents.

func (*Engine) BackendStatus

func (e *Engine) BackendStatus() BackendStatus

BackendStatus says which backend was chosen, or why there is none (for the doctor and the node page).

func (*Engine) Capabilities

func (e *Engine) Capabilities() engine.Capabilities

Capabilities: the interface is shared by all users of a profile, so no per-credential rate limit; a credential cannot expire by itself on the device (the agent withdraws it).

func (*Engine) Close

func (e *Engine) Close(ctx context.Context) error

Close removes every interface and closes the backend.

func (*Engine) Collect

func (e *Engine) Collect(ctx context.Context) (engine.Collected, error)

Collect returns traffic deltas since the previous Collect and the open sessions.

func (*Engine) Health

func (e *Engine) Health() []plugin.EngineHealth

Health is the run state per inbound. A running inbound whose interface vanished (or, in userspace, whose UDP port is no longer bound) is reported failed; the next Apply (or a restart) rebuilds it.

func (*Engine) Kick

func (e *Engine) Kick(ctx context.Context, credIDs []string) (int, error)

Kick closes the sessions of these credentials: the peer is removed and put back after a second if its credential is still valid (the client reconnects by its own timer, up to ~15 s). It returns how many credentials had a session.

func (*Engine) Observed

func (e *Engine) Observed() []statehash.Inbound

Observed reports what the device actually holds: a credential counts only while its public key and allowed ips are on the interface, so a peer that vanished shows up as a state-hash difference (state_drift). For an inbound that is not running (disabled, failed) the delivered credentials are reported, the failure is shown elsewhere.

func (*Engine) Protocol

func (e *Engine) Protocol() string

Protocol implements engine.Engine.

func (*Engine) Remove

func (e *Engine) Remove(ctx context.Context, inboundID string) error

Remove stops the inbound and forgets it.

func (*Engine) Version

func (e *Engine) Version() string

Version names the backend (EngineInfo.version).

type HealthReporter

type HealthReporter interface {
	AwgHealth() []InboundHealth
}

HealthReporter is what the agent asserts on the engine to fill InboundHealth.awg.

type InboundHealth

type InboundHealth struct {
	InboundID           string
	Backend             string
	BackendVersion      string
	IfaceUp             bool
	Peers               uint32
	PeersHandshaken     uint32 // completed a handshake at least once
	PeersOnline         uint32 // last handshake younger than 190 s
	NewestHandshakeUnix int64
	UnknownPeerEvents   uint32 // initiations from unknown keys since the previous health report
}

InboundHealth is the AWG-specific health of one inbound (agent.v1.AwgHealth without the UDP packet counter, which is an nftables counter the host layer owns).

type Options

type Options struct {
	// Backend is NodeSettings.awg_backend: "auto" (the kernel module if it is already loaded, else userspace),
	// "kernel" or "userspace". "" means auto. Chosen once here; the agent does not install packages.
	Backend string
}

Options configure a new Engine.

Directories

Path Synopsis
Package awgcfg is the pure data model of an AmneziaWG interface shared by the node engine, the wire clients (awgnl, awguapi) and the panel plugin: settings JSON, the strict validator and the peer types.
Package awgcfg is the pure data model of an AmneziaWG interface shared by the node engine, the wire clients (awgnl, awguapi) and the panel plugin: settings JSON, the strict validator and the peer types.
Package awgnl talks to the amneziawg kernel module over generic netlink (family "amneziawg", WG_GENL_VERSION 3, the AWG 3.0/3.1 encoding).
Package awgnl talks to the amneziawg kernel module over generic netlink (family "amneziawg", WG_GENL_VERSION 3, the AWG 3.0/3.1 encoding).
Package awgtest is the test harness for AmneziaWG on Linux: network namespaces with veth pairs, real amneziawg-go clients built from the pinned source (never a downloaded binary), and small probes (ping, a "who do you see me as" TCP server, iperf3).
Package awgtest is the test harness for AmneziaWG on Linux: network namespaces with veth pairs, real amneziawg-go clients built from the pinned source (never a downloaded binary), and small probes (ping, a "who do you see me as" TCP server, iperf3).
Package awguapi renders and parses the UAPI text protocol of amneziawg-go v3.1.x (device.IpcSet / IpcGet).
Package awguapi renders and parses the UAPI text protocol of amneziawg-go v3.1.x (device.IpcSet / IpcGet).

Jump to

Keyboard shortcuts

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