awgcfg

package
v0.2.0-dev.13 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 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 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. It has no dependencies and no OS-specific code, so the panel can import it too.

Index

Constants

View Source
const (
	Version20 = "2.0"
	Version31 = "3.1"
)

Versions of the protocol a profile can speak.

Variables

This section is empty.

Functions

func CheckCPS

func CheckCPS(s string) (size int, err error)

CheckCPS validates one custom packet (an I1..I5 value) and returns its size in bytes. The grammar is the intersection of what amneziawg-go, the kernel module and the clients accept: a chain of <b 0xHEX> <r N> <rc N> <rd N> <t> with nothing between the tags, N in 1..1000, hex non-empty and even, at most one <t>. <c> is refused (only the module knows it, clients reject the config) and so is '#' (the comment character of .conf files).

func DecodeKey

func DecodeKey(s string) (k [32]byte, ok bool)

DecodeKey decodes a standard-base64 32-byte key.

Types

type Issue

type Issue struct {
	Pointer string
	Code    string // stable snake_case id
	Message string // short English fact
}

Issue is one finding of Validate. Pointer is a JSON pointer into the profile ("/obfuscation/s1").

func (Issue) Error

func (i Issue) Error() string

type Obfuscation

type Obfuscation struct {
	Preset string `json:"preset,omitempty"` // panel only: input of the generator, label in the UI

	Jc   int   `json:"jc"`
	Jmin int   `json:"jmin"`
	Jmax int   `json:"jmax"`
	S1   int   `json:"s1"`
	S2   int   `json:"s2"`
	S3   int   `json:"s3"`
	S4   int   `json:"s4"`
	H1   Range `json:"h1"`
	H2   Range `json:"h2"`
	H3   Range `json:"h3"`
	H4   Range `json:"h4"`

	I1 string `json:"i1,omitempty"` // client side only
	I2 string `json:"i2,omitempty"`
	I3 string `json:"i3,omitempty"`
	I4 string `json:"i4,omitempty"`
	I5 string `json:"i5,omitempty"`

	HeaderProtectionKey string `json:"header_protection_key,omitempty"` // base64, 32 bytes; 3.1 only; a secret
	RandomTrailers      bool   `json:"random_trailers,omitempty"`       // 3.1 only
	DisableCookies      bool   `json:"disable_cookies,omitempty"`       // 3.1 only, server side only

	ContentPaddingAddition Range `json:"content_padding_addition,omitzero"` // 3.1
	RekeyAfterTime         Range `json:"rekey_after_time,omitzero"`         // 3.1
	RekeyTimeout           Range `json:"rekey_timeout,omitzero"`            // 3.1
	RejectAfterTime        Range `json:"reject_after_time,omitzero"`        // 3.1
	KeepaliveTimeout       Range `json:"keepalive_timeout,omitzero"`        // 3.1
	MaxHandshakeAttempts   Range `json:"max_handshake_attempts,omitzero"`   // 3.1

	PersistentKeepalive Range `json:"persistent_keepalive,omitzero"` // client [Peer] only
}

Obfuscation is the "obfuscation" object of a profile. Field order is the order the node JSON is serialized in (it is hashed). Client-only fields (i1..i5, preset, persistent_keepalive) are part of the type because the panel uses it too; the node ignores what it does not need.

func (Obfuscation) H

func (o Obfuscation) H() [4]Range

H returns h1..h4.

func (Obfuscation) HPK

func (o Obfuscation) HPK() (key *[32]byte, ok bool)

HPK decodes the header protection key: nil when unset, ok=false when malformed.

func (Obfuscation) I

func (o Obfuscation) I() [5]string

I returns i1..i5.

func (Obfuscation) S

func (o Obfuscation) S() [4]int

S returns s1..s4.

func (Obfuscation) Timers

func (o Obfuscation) Timers() [6]Range

Timers returns the six 3.1 range fields in the order: content_padding_addition, rekey_after_time, rekey_timeout, reject_after_time, keepalive_timeout, max_handshake_attempts.

type Options

type Options struct {
	MTU int // tunnel MTU: enables the jmax >= mtu and mtu > 1280 warnings
}

Options are the facts outside Settings that some rules need. Zero values skip the rule.

type Peer

type Peer struct {
	PublicKey  [32]byte
	PSK        *[32]byte
	AllowedIPs []netip.Prefix
	Endpoint   string // "host:port", client side only
	Keepalive  Range  // client side only
	Remove     bool   // the session dies at once; re-adding costs the client up to ~15 s
	UpdateOnly bool   // never creates a peer: the safe way to change a live one
	ReplaceIPs bool   // replace the allowed ips instead of adding
}

Peer is one peer operation for a backend or a wire client. Endpoint and Keepalive are for the client side (tests; the engine never sets them on a server: a server that sets keepalive starts initiating handshakes).

type PeerStat

type PeerStat struct {
	PublicKey  [32]byte
	RxBytes    uint64    // client -> node (plugin.UserTraffic.Up)
	TxBytes    uint64    // node -> client (plugin.UserTraffic.Down)
	LastHS     time.Time // zero = never
	Endpoint   netip.AddrPort
	AllowedIPs []netip.Prefix
}

PeerStat is one peer as a device reports it.

func MergeStats added in v0.1.44

func MergeStats(in []PeerStat) []PeerStat

MergeStats folds entries that share a public key into one, keeping the first-seen order. A kernel dump message can end between two allowed ips of one peer and repeat the peer, with only its key and the remaining allowed ips, in the next message. Allowed ips are concatenated without exact duplicates; every other field is taken from the first entry that has it (a continuation carries zero counters).

type Range

type Range struct {
	Lo, Hi uint32
	// contains filtered or unexported fields
}

Range is an "n" or "lo-hi" value. The zero value means "unset". In JSON it is a string; a bare number and "" are accepted on input.

func ParseRange

func ParseRange(s string) (Range, error)

ParseRange parses "n" or "lo-hi" (both ends uint32); "" is the zero Range.

func (Range) IsZero

func (r Range) IsZero() bool

IsZero reports whether the range is unset (or an explicit 0).

func (Range) MarshalJSON

func (r Range) MarshalJSON() ([]byte, error)

func (Range) String

func (r Range) String() string

String renders "n" or "lo-hi" (what UAPI and .conf files take); callers skip zero ranges.

func (*Range) UnmarshalJSON

func (r *Range) UnmarshalJSON(b []byte) error

type Result

type Result struct {
	Errors   []Issue
	Warnings []Issue
}

Result is what Validate found. Errors make the profile unusable; Warnings do not.

func Validate

func Validate(s Settings, opt Options) Result

Validate applies the rules that concern the settings themselves (port, subnets and the backend's capabilities are checked by whoever owns those facts). The same code runs in the panel plugin's Validate and again in the agent's Apply.

func (Result) Err

func (r Result) Err() error

Err joins the errors into one error (nil when OK).

func (Result) OK

func (r Result) OK() bool

OK reports whether there is no error.

type Settings

type Settings struct {
	Version     string      `json:"version"`
	PrivateKey  string      `json:"private_key,omitempty"` // base64; the inbound's server key, a secret; node JSON only
	Obfuscation Obfuscation `json:"obfuscation"`
}

Settings is the settings_json of an awg inbound (and, with the client-only fields, of the profile). Port, mtu, egress and the subnets are first-class InboundSpec fields (listen, tunnel, egress), not settings.

func ParseSettings

func ParseSettings(raw []byte) (Settings, error)

ParseSettings reads a settings document. Unknown keys are ignored (the panel may add fields without a lock-step node upgrade); values are not validated here, see Validate.

func (Settings) NodeJSON

func (s Settings) NodeJSON() ([]byte, error)

NodeJSON is the canonical settings_json for a node: the client-only fields (i1..i5, preset, persistent_keepalive) are dropped and fields come out in a fixed order. The bytes go into the spec hash.

Jump to

Keyboard shortcuts

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