Documentation
¶
Overview ¶
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). The engine tests in internal/node/awg use it; the end-to-end stand and the synthetic checks are meant to reuse it.
Rules it enforces: it runs only when MG_ROOT_TESTS=1 and as root, only in WSL or on a throwaway VM, never on a fleet host; every namespace it creates is named with the prefix "mg3-awg-" so that several sessions sharing one WSL cannot delete each other's objects; processes are killed and namespaces removed at the end of each test, and leftovers of a crashed run (same prefix, no other owner) are removed on the next start. It never starts QEMU/KVM.
Everything is in *_linux.go files; on other systems the package is empty and only compiles.
Index ¶
- Constants
- func B64(k [32]byte) string
- func CacheDir() string
- func CleanupStale()
- func ClientBin(t testing.TB, flavor string) string
- func NewKey(t testing.TB) (priv, pub [32]byte)
- func Ping(ns NS, target string, count, size int, df bool, interval time.Duration, ...) (loss int, out string)
- func Require(t testing.TB)
- func Veth(t testing.TB, a NS, aName string, aAddrs []string, b NS, bName string, ...)
- func Wait(timeout time.Duration, ok func() bool) bool
- func Whoami(ns NS, host string, port int) string
- type Client
- type ClientCfg
- type NS
- type Proc
Constants ¶
const ( Flavor31 = "3.1" // amneziawg-go v3.1.20260828 (the pin) Flavor30 = "3.0" // amneziawg-go v3.0.20260805: no RandomTrailers / DisableCookies Flavor20 = "2.0" // amneziawg-go v0.2.17, the last of the 2.0 line )
Flavor names a client implementation: which AmneziaWG generation it speaks.
const Prefix = "mg3-awg-"
Prefix is the name prefix of every namespace this package creates.
Variables ¶
This section is empty.
Functions ¶
func CacheDir ¶
func CacheDir() string
CacheDir is where client binaries are kept between runs (MG3_TEST_CACHE, default ~/.cache/mistgate-tests).
func CleanupStale ¶
func CleanupStale()
CleanupStale deletes namespaces named Prefix* left by a crashed run, after killing what runs in them. It touches nothing else.
func ClientBin ¶
ClientBin returns the path of the amneziawg-go binary of the flavor, building it from the pinned source with `go install` on first use (needs the network and a Go toolchain; a binary is never downloaded).
func NewKey ¶
NewKey returns an X25519 key pair (the private key is the raw scalar; WireGuard clamps it).
func Ping ¶
func Ping(ns NS, target string, count, size int, df bool, interval time.Duration, extra ...string) (loss int, out string)
Ping sends count echo requests from ns to target and returns the packet loss in percent and the tool output. size is the ICMP payload (0 = default); df sets "do not fragment". interval 0 = default 1 s; extra are more ping options, for example "-I", "<interface>".
func Require ¶
Require skips the test unless root tests are enabled, and removes leftovers of a crashed earlier run.
func Veth ¶
Veth creates a veth pair between a and b with the given names and CIDR addresses on each end, all up.
Types ¶
type Client ¶
Client is a real amneziawg-go process in a namespace.
func StartClient ¶
StartClient starts amneziawg-go in ns, configures it over its UAPI socket, addresses the TUN and brings it up. It does not wait for a handshake.
func (*Client) Handshaken ¶
Handshaken reports whether the client completed a handshake with the server.
func (*Client) LastHandshake ¶
LastHandshake is the time of the client's most recent handshake (zero = never).
func (*Client) ReplacePeer ¶
ReplacePeer configures the server peer again from scratch (the old one is removed first): the session keys are gone and the next packet makes the client start a new handshake. The benchmark suite uses it to count handshakes.
type ClientCfg ¶
type ClientCfg struct {
Flavor string // Flavor31 | Flavor30 | Flavor20
Addrs []string
Routes []string // destinations sent into the tunnel
Priv [32]byte
ServerPub [32]byte
PSK *[32]byte
Endpoint string // "203.0.113.10:51842"
Obf awgcfg.Obfuscation
MTU int // 0 = 1280
Keepalive string // "25"; "" = none
}
ClientCfg is one client interface.
type NS ¶
type NS struct{ Name string }
NS is a network namespace created for one test.
func NewNS ¶
NewNS creates "mg3-awg-<suffix>" with lo up and deletes it (and kills its processes) when the test ends.
type Proc ¶
type Proc struct {
Stdin io.WriteCloser // closing it is the polite way to ask a helper to stop
// contains filtered or unexported fields
}
Proc is a process started in a namespace; it is killed at the end of the test.
func StartWhoami ¶
StartWhoami runs a TCP server in ns that answers "peer=<your address>" and closes: the way to see which source address (after masquerade) a connection arrived with.