network

package
v0.5.4 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2026 License: MIT Imports: 7 Imported by: ? 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 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

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

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

type AuthType int

AuthType identifies the WiFi authentication method.

const (
	// AuthPSK uses WPA2/WPA3 pre-shared key authentication.
	AuthPSK AuthType = iota + 1
	// AuthEAPTLS uses 802.1X EAP-TLS certificate-based authentication.
	AuthEAPTLS
)

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.

const NetworkManager Backend = iota + 1

NetworkManager wraps nmcli.

func Detect

func Detect(ctx context.Context) []Backend

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.

func New

func New(b Backend, runner exec.Runner, _ ...Option) (Manager, error)

New returns a Manager for the named backend, driven by runner. Pure: validates the backend is known; it does not probe the host (use Detect). The zero value and any unimplemented backend are rejected with ErrUnknownBackend.

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.

Jump to

Keyboard shortcuts

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