vzdctl

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package vzdctl is the control channel between the clawk CLI and a running vzd daemon: a tiny HTTP API served over a unix socket in the sandbox's VM dir. It exists so network-policy edits apply to the live VM (no down/up cycle) and so the CLI can read the daemon's denial ledger.

Index

Constants

View Source
const (
	LifecycleBooting = "booting"
	LifecycleRunning = "running"
	LifecyclePaused  = "paused"
)

Lifecycle state values for LifecycleState.State.

View Source
const SocketName = "control.sock"

SocketName is the control socket's filename inside a sandbox's VM dir, next to vz.pid and agent.sock.

Variables

View Source
var ErrLifecycleUnsupported = errors.New("daemon does not support lifecycle control (restart the sandbox to upgrade its daemon)")

ErrLifecycleUnsupported reports that the daemon answered but has no lifecycle endpoints — it predates lifecycle control. Callers check with errors.Is and suggest a sandbox restart.

View Source
var ErrNotRunning = errors.New("control socket not available (sandbox not running?)")

ErrNotRunning reports that no daemon is listening — the sandbox is down (or predates the control socket). Callers check with errors.Is.

View Source
var ErrReverseForwardsUnsupported = errors.New("daemon does not support reverse port forwarding")

ErrReverseForwardsUnsupported reports that the daemon answered but has no reverse-forward endpoint — either it predates the feature or its backend has no host-side vsock listener (firecracker). Callers check with errors.Is.

View Source
var ErrSerialUnsupported = errors.New("daemon does not support serial forwarding")

ErrSerialUnsupported reports that the daemon answered but has no serial endpoint — either it predates the feature or its backend has no host-side vsock listener (firecracker). Callers check with errors.Is.

Functions

func SocketPath

func SocketPath(vmDir string) string

SocketPath returns the control socket path for a sandbox's VM dir.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client talks to a vzd control socket. The zero value is not usable; build one with NewClient.

func NewClient

func NewClient(path string) *Client

NewClient returns a client for the control socket at path. It does not dial; connection errors surface on the first call.

func (*Client) AllowAll

func (c *Client) AllowAll(ctx context.Context, d time.Duration) error

AllowAll opens the time-boxed allow-all bypass for d (every destination passes until it elapses) and releases any currently held connections. A non-positive d clears the bypass.

func (*Client) Decide

func (c *Client) Decide(ctx context.Context, id, action, scope string) error

Decide resolves a held connection by id. action is "allow" or "deny"; scope is "once", "session", or "always". It returns ErrUnknownDecision (wrapped) when the hold is no longer outstanding.

func (*Client) Denials

func (c *Client) Denials(ctx context.Context) ([]netfilter.Denial, error)

Denials fetches the daemon's denial ledger, most recent first.

func (*Client) Events

func (c *Client) Events(ctx context.Context) (<-chan netfilter.Event, error)

Events streams gate events (pending/resolved) over the control socket. The returned channel is closed when ctx is cancelled or the stream ends; the reader goroutine's lifetime is bound to ctx. Connection errors surface from Events itself, not the channel.

func (*Client) Lifecycle

func (c *Client) Lifecycle(ctx context.Context) (LifecycleState, error)

Lifecycle fetches the VM's live lifecycle snapshot.

func (*Client) Pause

func (c *Client) Pause(ctx context.Context) error

Pause asks the daemon to suspend the guest's vCPUs in place.

func (*Client) Pending

func (c *Client) Pending(ctx context.Context) ([]netfilter.Pending, error)

Pending fetches the daemon's outstanding interactive holds.

func (*Client) Reload

func (c *Client) Reload(ctx context.Context) error

Reload asks the daemon to re-read the sandbox's network policy from the store and apply it to the live allow list.

func (*Client) ReloadForwards added in v0.3.0

func (c *Client) ReloadForwards(ctx context.Context) error

ReloadForwards asks the daemon to re-read the sandbox's reverse port forwards from the store and push them to the in-guest agent.

func (*Client) ReloadSerials added in v0.4.0

func (c *Client) ReloadSerials(ctx context.Context) error

ReloadSerials asks the daemon to re-read the sandbox's serial devices from the store and push them to the in-guest agent.

func (*Client) Resume

func (c *Client) Resume(ctx context.Context) error

Resume asks the daemon to restart the vCPUs after a Pause.

func (*Client) Suspend

func (c *Client) Suspend(ctx context.Context) error

Suspend asks the daemon to save the VM's memory + device state to disk and stop without resuming; the daemon exits shortly after the call returns. Blocking — pass a ctx generous enough to write a multi-GiB memory image.

type Handlers

type Handlers struct {
	// Denials returns the current denial ledger snapshot.
	Denials func() []netfilter.Denial

	// Reload re-reads the sandbox's network policy from the store and
	// applies it to the live allow list.
	Reload func() error

	// ReloadForwards, if non-nil, re-reads the sandbox's reverse port
	// forwards from the store and pushes them to the in-guest agent. Nil
	// on backends with no vsock listener (firecracker), where the endpoint
	// reports 404 and the client maps it to
	// ErrReverseForwardsUnsupported.
	ReloadForwards func() error

	// ReloadSerials, if non-nil, re-reads the sandbox's serial devices from
	// the store and pushes them to the in-guest agent. Nil on backends with
	// no vsock listener (firecracker), where the endpoint reports 404 and
	// the client maps it to ErrSerialUnsupported.
	ReloadSerials func() error

	// Gate, if non-nil, powers the interactive allow/deny endpoints
	// (/v1/events, /v1/decide, /v1/pending). When nil those endpoints
	// report 404 and the daemon serves only the denial ledger + reload.
	Gate *netfilter.Gate

	// Lifecycle, if non-nil, powers the VM lifecycle endpoints
	// (/v1/lifecycle, /v1/pause, /v1/resume, /v1/suspend). When nil those
	// endpoints report 404, which the client maps to
	// ErrLifecycleUnsupported — the daemon predates lifecycle control.
	Lifecycle *LifecycleHandlers
}

Handlers are the daemon-side callbacks the server dispatches to. Denials and Reload are required; Gate is optional.

type LifecycleHandlers

type LifecycleHandlers struct {
	// State reports the VM's live lifecycle snapshot.
	State func() LifecycleState

	// Pause suspends the guest's vCPUs in place (memory stays resident).
	Pause func() error

	// Resume restarts the vCPUs after a Pause.
	Resume func() error

	// Suspend saves memory + device state to disk and stops the VM without
	// resuming it; the daemon exits shortly after. Blocking — the response
	// is written only once the state file is on disk.
	Suspend func() error
}

LifecycleHandlers are the daemon-side callbacks behind the VM lifecycle endpoints. State is required when the struct is set; the verbs may be nil individually (each nil verb reports 404).

type LifecycleState

type LifecycleState struct {
	// State is "booting" (machine not constructed yet), "running", or
	// "paused".
	State string `json:"state"`
	// Restored reports whether this boot restored the guest from a
	// suspend-to-disk state file rather than cold-booting it. Callers use
	// it to skip boot-time hooks whose effects survived inside the guest.
	Restored bool `json:"restored"`
}

LifecycleState is the wire shape of GET /v1/lifecycle.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server serves the control API on a unix socket until Close.

func Start

func Start(path string, h Handlers) (*Server, error)

Start removes any stale socket at path, listens, and serves the control API in a background goroutine that exits on Close.

func (*Server) Close

func (s *Server) Close() error

Close stops the server and removes the socket file.

Jump to

Keyboard shortcuts

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