Documentation
¶
Overview ¶
Package network manages WiFi connection profiles through an injected exec.Runner.
Build a Manager for an explicit backend (NetworkManager/nmcli is the only one today) and a Runner, then call its methods. Read verbs (ConnectionExists, Settings) run unprivileged; mutations (add/modify/delete, reload) escalate through the Runner.
r, _ := exec.NewRunner(exec.Direct) nm, _ := network.New(network.NetworkManager, r) changed, _ := nm.Apply(ctx, profile)
Credentials are exec.Secret values: the WPA PSK and the EAP-TLS client key never appear in a command's argv. The PSK is provisioned via a 0600 NetworkManager keyfile (then `nmcli connection reload`); the client key is written to a 0600 file in the profile's cert directory. Both Reveal() sinks are enumerated by the archtest fitness function.
Detect reports whether nmcli is usable on the host so a consumer can choose a backend explicitly.
Index ¶
Constants ¶
const CertBaseDir = "/var/lib/power-manage/wifi"
CertBaseDir is the expected parent directory for EAP-TLS cert directories. Apply and Delete validate CertDir against this (symlink-aware) so a profile can never read or remove files outside the managed tree.
Variables ¶
var ErrUnknownBackend = fmt.Errorf("network: unknown backend")
ErrUnknownBackend is returned by New for the zero value or any Backend the SDK does not implement (fail-closed).
Functions ¶
This section is empty.
Types ¶
type Backend ¶
type Backend int
Backend selects the WiFi-management implementation. Passed explicitly even though NetworkManager is the only value today; the zero value is invalid (New → ErrUnknownBackend). The never-implemented connman/wpa_supplicant/iwd scaffolds are not ported; a real second backend is appended here when actually written.
func Detect ¶
Detect reports the WiFi backends usable on THIS host: NetworkManager when nmcli is on PATH. It lists; it never picks and never constructs a Manager — the consumer reads the list, picks a backend explicitly, and passes it to New. An empty slice means no usable WiFi manager (the consumer falls through to its "wifi not supported" path). This folds the old IsAvailable probe.
The ctx is accepted for signature uniformity with the other capability Detect functions; the present probe is a pure PATH lookup.
type DeleteOptions ¶
type DeleteOptions struct {
CertDir string
}
DeleteOptions configures Delete. CertDir, when set, is the EAP-TLS cert directory to clean up after the connection is removed; it must be under CertBaseDir (validated, symlink-aware).
type Manager ¶
type Manager interface {
// ConnectionExists reports whether a named connection profile exists.
ConnectionExists(ctx context.Context, name string) (bool, error)
// Apply creates or updates a WiFi connection profile, returning whether a
// change was made.
Apply(ctx context.Context, p Profile) (changed bool, err error)
// Delete removes a connection by name and, if opts.CertDir is set, cleans up
// its cert directory.
Delete(ctx context.Context, name string, opts DeleteOptions) error
// Settings returns the current connection settings as a key-value map,
// unescaped from nmcli terse-mode encoding.
Settings(ctx context.Context, name string) (map[string]string, error)
}
Manager is the WiFi-management contract.
type Option ¶
type Option func(*networkManager)
Option is the functional-option type for backend-specific knobs (none today).
type Profile ¶
type Profile struct {
Name string // connection name (e.g. "pm-wifi-<id>")
SSID string // WiFi network SSID
AuthType AuthType // AuthPSK or AuthEAPTLS
PSK exec.Secret // WPA2/WPA3 password (PSK only) — never enters argv
CACert string // PEM content (EAP-TLS only)
ClientCert string // PEM content (EAP-TLS only)
ClientKey exec.Secret // PEM content (EAP-TLS only) — never enters argv
Identity string // EAP identity (EAP-TLS only)
AutoConnect bool
Hidden bool
Priority int
CertDir string // directory for EAP-TLS cert files (must be under CertBaseDir)
}
Profile is a NetworkManager WiFi connection profile.