awgtest

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: AGPL-3.0 Imports: 21 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 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

View Source
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.

View Source
const Prefix = "mg3-awg-"

Prefix is the name prefix of every namespace this package creates.

Variables

This section is empty.

Functions

func B64

func B64(k [32]byte) string

B64 is the base64 form of a key as it appears in credential data and settings.

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

func ClientBin(t testing.TB, flavor string) string

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

func NewKey(t testing.TB) (priv, pub [32]byte)

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

func Require(t testing.TB)

Require skips the test unless root tests are enabled, and removes leftovers of a crashed earlier run.

func Veth

func Veth(t testing.TB, a NS, aName string, aAddrs []string, b NS, bName string, bAddrs []string)

Veth creates a veth pair between a and b with the given names and CIDR addresses on each end, all up.

func Wait

func Wait(timeout time.Duration, ok func() bool) bool

Wait polls until ok returns true or the timeout passes.

func Whoami

func Whoami(ns NS, host string, port int) string

Whoami connects from ns to a StartWhoami server and returns the address it saw ("" on failure).

Types

type Client

type Client struct {
	NS    NS
	Iface string
	// contains filtered or unexported fields
}

Client is a real amneziawg-go process in a namespace.

func StartClient

func StartClient(t testing.TB, ns NS, cfg ClientCfg) *Client

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 StartServer

func StartServer(t testing.TB, ns NS, cfg ServerCfg) *Client

StartServer starts amneziawg-go in ns listening on cfg.Port (both IPv4 and IPv6), adds the peers, addresses the TUN and brings it up. The returned Client is only a handle on the process: use Stats/Peer, not Handshaken.

func (*Client) Handshaken

func (c *Client) Handshaken() bool

Handshaken reports whether the client completed a handshake with the server.

func (*Client) LastHandshake

func (c *Client) LastHandshake() time.Time

LastHandshake is the time of the client's most recent handshake (zero = never).

func (*Client) Output

func (c *Client) Output() string

Output is what the client process printed (errors only: LOG_LEVEL=error).

func (*Client) Peer

func (c *Client) Peer(pub [32]byte) (awgcfg.PeerStat, bool)

Peer is the interface's current view of one peer (endpoint, last handshake, counters).

func (*Client) ReplacePeer

func (c *Client) ReplacePeer(cfg ClientCfg) error

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.

func (*Client) SetEndpointText

func (c *Client) SetEndpointText(pub [32]byte, endpoint string) string

SetEndpointText sends a raw peer "endpoint=" line and returns the UAPI error ("" = accepted). It is how a test finds out what the daemon does with a host name (it does not resolve: that is the config tool's job).

func (*Client) Stats

func (c *Client) Stats() ([]awgcfg.PeerStat, error)

Stats reads the client's view of its peers.

func (*Client) Stop

func (c *Client) Stop()

Stop ends the client process (its TUN goes with it).

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

func NewNS(t testing.TB, suffix string) NS

NewNS creates "mg3-awg-<suffix>" with lo up and deletes it (and kills its processes) when the test ends.

func (NS) Cmd

func (n NS) Cmd(args ...string) *exec.Cmd

Cmd builds a command that runs inside the namespace. The zero NS is the host itself (the benchmark suite's loopback mode).

func (NS) Must

func (n NS) Must(t testing.TB, args ...string) string

Must is Run that fails the test on error.

func (NS) Run

func (n NS) Run(args ...string) (string, error)

Run runs a command inside the namespace and returns its combined output.

func (NS) Start

func (n NS) Start(t testing.TB, env []string, args ...string) *Proc

Start runs a long-lived command in the namespace (its own process group, killed on cleanup).

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

func StartWhoami(t testing.TB, ns NS, host string, port int) *Proc

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.

func (*Proc) Exited

func (p *Proc) Exited(d time.Duration) bool

Exited waits up to d for the process to end on its own.

func (*Proc) Kill

func (p *Proc) Kill()

Kill ends the process group and waits for it.

func (*Proc) Output

func (p *Proc) Output() string

Output is everything the process printed so far.

func (*Proc) Pid

func (p *Proc) Pid() int

Pid is the process id (the benchmark suite reads its CPU time and memory from /proc).

type ServerCfg

type ServerCfg struct {
	Flavor string
	Addrs  []string // the interface's own addresses, CIDR
	Priv   [32]byte
	Port   uint16
	Obf    awgcfg.Obfuscation
	MTU    int // 0 = 1280
	Peers  []awgcfg.Peer
}

ServerCfg is a listening AmneziaWG interface: the exit of a relay test. Unlike the engine's stand it is a bare amneziawg-go process, so a test can give it any peers and read what it learned about them.

Jump to

Keyboard shortcuts

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