hostnet

package
v1.2.3 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 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 hostnet creates and removes bridges, bonds and VLAN interfaces on the host (ADR-0042) through whatever already manages the host's network: netplan, NetworkManager or systemd-networkd. VirtoMir never runs a network stack of its own.

A wrong network change can cut the host off, including the browser that made it. So every change is a transaction that must be confirmed from the browser within a deadline (by default two minutes); a confirmation that cannot reach the host is no confirmation, and the change is rolled back: files restored, created devices deleted, the previous configuration applied again. The pending transaction is saved first, so a daemon that dies in between rolls back when it starts.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalid = errors.New("invalid")
	ErrRefused = errors.New("refused")
)

ErrInvalid and ErrRefused classify errors for the API (400 / 409).

Functions

This section is empty.

Types

type Manager

type Manager struct {
	Root     string // "/" on a host; tests use a temporary directory
	StateDir string
	Run      Runner
	Log      *slog.Logger
	// Interfaces lists the host's interfaces (hostinfo); Window is the confirmation time.
	Interfaces func() []hostinfo.Interface
	Window     time.Duration
	LookPath   func(string) (string, error)
	// contains filtered or unexported fields
}

Manager applies changes one at a time.

func New

func New(stateDir string, log *slog.Logger, h *hostinfo.Reader) *Manager

New returns a manager for the real host. It rolls back a change left unconfirmed by a previous run.

func (*Manager) Confirm

func (m *Manager) Confirm(id string) error

Confirm keeps a pending change.

func (*Manager) Create

func (m *Manager) Create(ctx context.Context, s Spec) (*Pending, error)

Create adds an interface; it must be confirmed with Confirm before the window ends.

func (*Manager) Delete

func (m *Manager) Delete(ctx context.Context, name string) (*Pending, error)

Delete removes an interface VirtoMir created; also confirmed like Create.

func (*Manager) Records

func (m *Manager) Records() []Record

Records lists the interfaces VirtoMir created.

func (*Manager) Recover

func (m *Manager) Recover()

Recover rolls back a change a previous run left unconfirmed.

func (*Manager) Rollback

func (m *Manager) Rollback(id string) error

Rollback undoes a pending change now.

func (*Manager) Status

func (m *Manager) Status() Status

type Pending

type Pending struct {
	ID       string    `json:"id"`
	What     string    `json:"what"`
	Backend  string    `json:"backend"`
	Started  time.Time `json:"started"`
	Deadline time.Time `json:"deadline"`

	Files   []fileSnap `json:"files,omitempty"`
	Undo    []cmd      `json:"undo,omitempty"`
	Reapply []cmd      `json:"reapply,omitempty"`
}

Pending is a change waiting for confirmation.

type Record

type Record struct {
	Spec
	Backend string    `json:"backend"`
	Created time.Time `json:"created"`
	// netplan: the address keys taken from TakeAddressFrom, to give back on removal.
	Moved string `json:"moved,omitempty"`
	// netplan: port definitions VirtoMir added (ports netplan did not know before).
	Added []string `json:"added,omitempty"`
	// NetworkManager: the connection each port had before, to bring back on removal, and
	// the commands that made it (to restore it if a removal is rolled back).
	OldConns map[string]string `json:"oldConns,omitempty"`
	Recreate []cmd             `json:"recreate,omitempty"`
}

Record is an interface VirtoMir created, with what is needed to remove it cleanly.

type Runner

type Runner func(ctx context.Context, args ...string) ([]byte, error)

Runner runs a command; tests replace it.

type Spec

type Spec struct {
	Kind string `json:"kind"` // bridge, bond, vlan
	Name string `json:"name"`
	// Ports: bridge ports or bond members.
	Ports    []string `json:"ports,omitempty"`
	BondMode string   `json:"bondMode,omitempty"` // active-backup (default), 802.3ad, balance-alb, balance-tlb, balance-xor, broadcast, balance-rr
	STP      bool     `json:"stp,omitempty"`
	// vlan: Parent interface and VLAN ID.
	Parent string `json:"parent,omitempty"`
	VLAN   int    `json:"vlan,omitempty"`
	// TakeAddressFrom names a port whose IP configuration (DHCP or static addresses,
	// routes, DNS) moves to the new bridge or bond: the usual way to put the host's own
	// uplink into a bridge for machines without losing the host's address.
	TakeAddressFrom string `json:"takeAddressFrom,omitempty"`
}

Spec is a new host interface.

type Status

type Status struct {
	Backend string   `json:"backend"` // netplan, networkmanager, networkd, "" (unsupported)
	Reason  string   `json:"reason,omitempty"`
	Pending *Pending `json:"pending,omitempty"`
	Created []Record `json:"created"`
}

Status is what the UI shows: the backend in charge, the pending change, VirtoMir's own interfaces.

Jump to

Keyboard shortcuts

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