network

package
v0.51.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AttachTAP

func AttachTAP(tapName, bridgeName string) error

AttachTAP adds a TAP interface to a bridge using ip link set master.

func CreateBridge

func CreateBridge(cfg BridgeConfig) error

CreateBridge creates a Linux bridge, assigns the gateway IP, and brings it up. Requires CAP_NET_ADMIN.

func CreateTAPDevice

func CreateTAPDevice(name string) error

CreateTAPDevice creates a persistent TAP device by name. It is idempotent: a device that already exists is treated as success. Firecracker requires the tap to exist before it opens it; unlike QEMU it does not create taps itself.

func DeleteTAPDevice

func DeleteTAPDevice(name string) error

DeleteTAPDevice removes a persistent TAP device created by CreateTAPDevice.

func DestroyBridge

func DestroyBridge(name string) error

DestroyBridge removes a Linux bridge interface.

func DetachTAP

func DetachTAP(tapName string) error

DetachTAP removes a TAP interface from its bridge.

func EnsureBridge

func EnsureBridge(cfg BridgeConfig) error

EnsureBridge creates the bridge if it does not already exist, assigning the gateway IP and bringing it up. Unlike CreateBridge it is idempotent, so it is safe to call for a bridge shared by multiple VMs.

Types

type BridgeConfig

type BridgeConfig struct {
	// Name is the bridge interface name (e.g. "jerboa-br0").
	Name string
	// CIDR is the gateway IP with CIDR mask (e.g. "10.0.0.1/24").
	CIDR string
}

BridgeConfig holds the parameters for a Linux bridge interface.

type Forwarder

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

Forwarder publishes guest ports on the host by proxying real listening sockets to the guest over the bridge.

It replaces iptables DNAT, which never worked for host-local access (the PREROUTING rule matched the wrong direction) and is invisible to WSL2's localhost forwarding (a DNAT rule opens no listening socket, so a Windows host cannot reach it). A userspace listener is a normal socket: reachable from the host itself and mirrored by WSL2 to the Windows side.

func StartForwarder

func StartForwarder(guestIP string, ports []PortForward) (*Forwarder, error)

StartForwarder opens a TCP listener for each TCP port map and proxies accepted connections to guestIP. UDP maps are not yet supported and are skipped with a warning. The returned Forwarder must be closed when the VM stops.

func (*Forwarder) Close

func (f *Forwarder) Close()

Close stops all listeners and waits for in-flight connections to drain.

type Network

type Network struct {
	ID        string    `json:"id"`
	Name      string    `json:"name"`
	Subnet    string    `json:"subnet"`
	Gateway   string    `json:"gateway"`
	Bridge    string    `json:"bridge"`
	Driver    string    `json:"driver"`
	CreatedAt time.Time `json:"created_at"`
}

type PortForward

type PortForward struct {
	HostPort  uint16
	GuestPort uint16
	Protocol  string
}

PortForward describes a single host-to-guest port forwarding rule.

type Store

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

func NewStore

func NewStore(dir string) (*Store, error)

func (*Store) AllocateIP

func (s *Store) AllocateIP(name string) (net.IP, error)

func (*Store) Create

func (s *Store) Create(name, subnet, driver string) (*Network, error)

func (*Store) Get

func (s *Store) Get(name string) (*Network, error)

func (*Store) List

func (s *Store) List() ([]*Network, error)

func (*Store) ReleaseIP

func (s *Store) ReleaseIP(name string, ip string) error

func (*Store) Remove

func (s *Store) Remove(name string) error

type TAP

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

TAP manages a TAP network interface.

func Create

func Create(cfg TAPConfig) (*TAP, error)

Create opens /dev/net/tun and creates a TAP interface with the given config. Requires CAP_NET_ADMIN.

func (*TAP) Destroy

func (t *TAP) Destroy() error

Destroy closes and removes the TAP interface.

func (*TAP) Name

func (t *TAP) Name() string

Name returns the interface name.

type TAPConfig

type TAPConfig struct {
	// Name is the interface name (e.g. "jerboa-tap0"). Truncated to 15 chars.
	Name string
	// Bridge is the Linux bridge to attach to (e.g. "jerboa-br0").
	Bridge string
}

TAPConfig holds the parameters for a TAP device.

Jump to

Keyboard shortcuts

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