route

package
v0.0.0-...-63dd1cf Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package route provides network route configuration management via Netplan.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Darwin

type Darwin struct{}

Darwin implements the Provider interface for Darwin (macOS). All methods return ErrUnsupported as Netplan is not available on macOS.

func NewDarwinProvider

func NewDarwinProvider() *Darwin

NewDarwinProvider factory to create a new Darwin instance.

func (*Darwin) Create

func (d *Darwin) Create(
	_ context.Context,
	_ Entry,
) (*Result, error)

Create returns ErrUnsupported on Darwin.

func (*Darwin) Delete

func (d *Darwin) Delete(
	_ context.Context,
	_ string,
) (*Result, error)

Delete returns ErrUnsupported on Darwin.

func (*Darwin) Get

func (d *Darwin) Get(
	_ context.Context,
	_ string,
) (*Entry, error)

Get returns ErrUnsupported on Darwin.

func (*Darwin) List

func (d *Darwin) List(
	_ context.Context,
) ([]ListEntry, error)

List returns ErrUnsupported on Darwin.

func (*Darwin) Update

func (d *Darwin) Update(
	_ context.Context,
	_ Entry,
) (*Result, error)

Update returns ErrUnsupported on Darwin.

type Debian

type Debian struct {
	provider.FactsAware
	// contains filtered or unexported fields
}

Debian implements the Provider interface for Debian-family systems. It writes Netplan YAML route files to /etc/netplan/ with an osapi- prefix and tracks state in the file-state KV for idempotency.

func NewDebianProvider

func NewDebianProvider(
	logger *slog.Logger,
	fs avfs.VFS,
	stateKV jetstream.KeyValue,
	execManager exec.Manager,
	hostname string,
) *Debian

NewDebianProvider factory to create a new Debian instance.

func (*Debian) Create

func (d *Debian) Create(
	ctx context.Context,
	entry Entry,
) (*Result, error)

Create deploys new routes for an interface via Netplan. Fails if a managed route file already exists for the interface, or if any route targets the default gateway.

func (*Debian) Delete

func (d *Debian) Delete(
	ctx context.Context,
	interfaceName string,
) (*Result, error)

Delete removes managed routes for an interface via Netplan. If no managed route file exists, returns Changed: false (idempotent).

func (*Debian) Get

func (d *Debian) Get(
	ctx context.Context,
	interfaceName string,
) (*Entry, error)

Get returns the managed routes for a specific interface by reading the route metadata from the file-state KV store.

func (*Debian) List

func (d *Debian) List(
	_ context.Context,
) ([]ListEntry, error)

List returns all routes from the system routing table, excluding kernel-internal entries (local, broadcast, anycast, multicast types and host-scoped routes).

func (*Debian) Update

func (d *Debian) Update(
	ctx context.Context,
	entry Entry,
) (*Result, error)

Update redeploys routes for an existing interface via Netplan. Fails if no managed route file exists for the interface, or if any route targets the default gateway.

type Entry

type Entry struct {
	Interface string  `json:"interface"`
	Routes    []Route `json:"routes"`
}

Entry represents managed routes for an interface.

type Linux

type Linux struct{}

Linux implements the Provider interface for generic Linux. All methods return ErrUnsupported as this is a generic Linux stub.

func NewLinuxProvider

func NewLinuxProvider() *Linux

NewLinuxProvider factory to create a new Linux instance.

func (*Linux) Create

func (l *Linux) Create(
	_ context.Context,
	_ Entry,
) (*Result, error)

Create returns ErrUnsupported on generic Linux.

func (*Linux) Delete

func (l *Linux) Delete(
	_ context.Context,
	_ string,
) (*Result, error)

Delete returns ErrUnsupported on generic Linux.

func (*Linux) Get

func (l *Linux) Get(
	_ context.Context,
	_ string,
) (*Entry, error)

Get returns ErrUnsupported on generic Linux.

func (*Linux) List

func (l *Linux) List(
	_ context.Context,
) ([]ListEntry, error)

List returns ErrUnsupported on generic Linux.

func (*Linux) Update

func (l *Linux) Update(
	_ context.Context,
	_ Entry,
) (*Result, error)

Update returns ErrUnsupported on generic Linux.

type ListEntry

type ListEntry struct {
	Destination string `json:"destination"`
	Gateway     string `json:"gateway"`
	Interface   string `json:"interface"`
	Mask        string `json:"mask,omitempty"`
	Metric      int    `json:"metric,omitempty"`
	Flags       string `json:"flags,omitempty"`
}

ListEntry is a route from the system routing table.

type Provider

type Provider interface {
	// List returns all routes from the system routing table.
	List(ctx context.Context) ([]ListEntry, error)
	// Get returns the managed routes for a specific interface.
	Get(ctx context.Context, interfaceName string) (*Entry, error)
	// Create deploys new routes for an interface via Netplan.
	Create(ctx context.Context, entry Entry) (*Result, error)
	// Update redeploys routes for an existing interface via Netplan.
	Update(ctx context.Context, entry Entry) (*Result, error)
	// Delete removes managed routes for an interface via Netplan.
	Delete(ctx context.Context, interfaceName string) (*Result, error)
}

Provider manages route configuration via Netplan.

type Result

type Result struct {
	Interface string `json:"interface"`
	Changed   bool   `json:"changed"`
	Error     string `json:"error,omitempty"`
}

Result is the outcome of a route create/update/delete operation.

type Route

type Route struct {
	To     string `json:"to"`
	Via    string `json:"via"`
	Metric int    `json:"metric,omitempty"`
}

Route is a single route definition.

Directories

Path Synopsis
Package mocks provides mock implementations for testing.
Package mocks provides mock implementations for testing.

Jump to

Keyboard shortcuts

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