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
- Variables
- func FactoryFor(backend string) engine.Factory
- func IfaceName(port uint16) string
- func New(env engine.Env) (engine.Engine, error)
- type BackendStatus
- type Engine
- func (e *Engine) Apply(ctx context.Context, spec plugin.InboundSpec, creds []plugin.UserCred) (engine.ApplyReport, error)
- func (e *Engine) AwgHealth() []InboundHealth
- func (e *Engine) BackendStatus() BackendStatus
- func (e *Engine) Capabilities() engine.Capabilities
- func (e *Engine) Close(ctx context.Context) error
- func (e *Engine) Collect(ctx context.Context) (engine.Collected, error)
- func (e *Engine) Health() []plugin.EngineHealth
- func (e *Engine) KernelDebugInfo() (bool, []KernelDebugInterface)
- func (e *Engine) Kick(ctx context.Context, credIDs []string) (int, error)
- func (e *Engine) Observed() []statehash.Inbound
- func (e *Engine) Protocol() string
- func (e *Engine) Remove(ctx context.Context, inboundID string) error
- func (e *Engine) Version() string
- func (e *Engine) WatchKernelUnknownPeers(fn func(ifname string)) (bool, func())
- type HealthReporter
- type InboundHealth
- type KernelDebugInterface
- type Options
Constants ¶
const ( ReasonModuleTooOld = "awg_module_too_old" )
Reasons the engine reports (InboundResult.error / Health detail start with the code).
const Protocol = "awg"
Protocol is the plugin id this engine serves.
Variables ¶
var Factory engine.Factory = New
Factory is the engine.Factory with the default (auto) backend choice; FactoryFor takes the setting.
Functions ¶
func FactoryFor ¶
FactoryFor returns a factory for the given NodeSettings.awg_backend.
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 ¶
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) Collect ¶
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) KernelDebugInfo ¶
func (e *Engine) KernelDebugInfo() (bool, []KernelDebugInterface)
KernelDebugInfo reports whether the engine uses the kernel backend and which active interfaces belong to each inbound.
func (*Engine) Kick ¶
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 ¶
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) WatchKernelUnknownPeers ¶
WatchKernelUnknownPeers forwards kernel unknown-peer events until the returned stop function is called.
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 KernelDebugInterface ¶
KernelDebugInterface identifies an active AWG kernel interface without exposing the engine's internal state.
Source Files
¶
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). |