network

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package network reads and changes a unit's IP networking: the WAN and LAN configuration, the logical network interfaces, UPnP/NAT-PMP and QoS. The DHCP server and port forwarding are in packages dhcp and portforward.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetQoS

func GetQoS(ctx context.Context, c *amplifi.Client) (map[string]any, error)

GetQoS fetches the QoS configuration as decoded JSON; its schema is unknown.

func SetQoS

func SetQoS(ctx context.Context, c *amplifi.Client, cfg map[string]any) error

SetQoS replaces the QoS configuration. cfg is sent as JSON and should have the shape GetQoS returns.

func UpdateConfig

func UpdateConfig(ctx context.Context, c *amplifi.Client, u ConfigUpdate) error

UpdateConfig applies u with a read-modify-write of the network configuration. Changing the WAN settings can cut the connection to the internet, and changing the LAN gateway the connection to the unit.

func UpdateInterface

func UpdateInterface(ctx context.Context, c *amplifi.Client, ifname string, u InterfaceUpdate) error

UpdateInterface changes the interface named ifname. It reads all interfaces, applies u to that one and writes them all back.

func UpdateUPnP

func UpdateUPnP(ctx context.Context, c *amplifi.Client, u UPnPUpdate) error

UpdateUPnP applies u with a read-modify-write.

Types

type Config

type Config struct {
	WANType       string       `json:"wan_type"`
	WANBridge     bool         `json:"wan_bridge"`
	WANStaticAddr netip.Prefix `json:"wan_static_addr,omitzero"`
	WANGateway    netip.Addr   `json:"wan_gateway,omitzero"`
	WANDNS        []netip.Addr `json:"wan_dns"`
	WANUsername   string       `json:"wan_username,omitempty"`
	WANPassword   string       `json:"wan_password,omitempty"`
	WANVLAN       int          `json:"wan_vlan"`
	WANMAC        amplifi.MAC  `json:"wan_mac,omitempty"`
	WAN6Protocol  string       `json:"wan6_protocol,omitempty"`
	WAN6ClientID  string       `json:"wan6_client_id,omitempty"`
	HWNAT         bool         `json:"hw_nat"`
	HomeKit       bool         `json:"homekit"`
	LANGateway    netip.Prefix `json:"lan_gateway,omitzero"`
	GuestGateway  netip.Prefix `json:"guest_gateway,omitzero"`
	IoTGateway    netip.Prefix `json:"iot_gateway,omitzero"`

	WANUp              bool           `json:"wan_up"`
	RuntimeWANAddress  netip.Prefix   `json:"runtime_wan_address,omitzero"`
	RuntimeWANGateway  netip.Addr     `json:"runtime_wan_gateway,omitzero"`
	RuntimeWANDNS      []netip.Addr   `json:"runtime_wan_dns"`
	WAN6Up             bool           `json:"wan6_up"`
	RuntimeWAN6Address []netip.Prefix `json:"runtime_wan6_address"`
	RuntimeWAN6Gateway []netip.Addr   `json:"runtime_wan6_gateway"`
	RuntimeWAN6DNS     []netip.Addr   `json:"runtime_wan6_dns"`
}

Config is the WAN and LAN addressing (GetNetworkConfig). An address the router stores without a prefix length gets a full-length prefix. The Runtime* fields are what is in use right now and cannot be set.

func GetConfig

func GetConfig(ctx context.Context, c *amplifi.Client) (*Config, error)

GetConfig fetches the WAN and LAN configuration.

func (Config) Redacted

func (cfg Config) Redacted() Config

Redacted returns a copy of cfg with the PPPoE password masked.

type ConfigUpdate

type ConfigUpdate struct {
	// WANType is a protocol name, usually "dhcp", "static" or "pppoe".
	WANType       *string
	WANBridge     *bool
	WANStaticAddr *netip.Prefix
	WANGateway    *netip.Addr
	// WANDNS replaces the static DNS servers when non-nil; an empty slice
	// clears them.
	WANDNS      []netip.Addr
	WANUsername *string
	WANPassword *string
	WANVLAN     *int
	// WANMAC overrides the WAN MAC address; an empty MAC restores the
	// default.
	WANMAC       *amplifi.MAC
	WAN6Protocol *string
	WAN6ClientID *string
	HWNAT        *bool
	LANGateway   *netip.Prefix
	GuestGateway *netip.Prefix
	IoTGateway   *netip.Prefix
}

ConfigUpdate lists the network settings to change; nil fields are left as they are. Addresses must be IPv4; a zero address or prefix clears the setting.

type Interface

type Interface struct {
	Name           string       `json:"name"`
	Device         string       `json:"device"`
	Enabled        bool         `json:"enabled"`
	Protocol       string       `json:"protocol"`
	Address        netip.Prefix `json:"address,omitzero"`
	Gateway        netip.Addr   `json:"gateway,omitzero"`
	DNS            netip.Addr   `json:"dns,omitzero"`
	Username       string       `json:"username,omitempty"`
	Password       string       `json:"password,omitempty"`
	Up             bool         `json:"up"`
	RuntimeAddress netip.Prefix `json:"runtime_address,omitzero"`
	RuntimeGateway netip.Addr   `json:"runtime_gateway,omitzero"`
	RuntimeDNS     []netip.Addr `json:"runtime_dns"`
}

Interface is one logical network interface (GetNetworkInterfaces).

func Interfaces

func Interfaces(ctx context.Context, c *amplifi.Client) ([]Interface, error)

Interfaces lists the unit's logical network interfaces, sorted by name.

func (Interface) Redacted

func (i Interface) Redacted() Interface

Redacted returns a copy of i with the PPPoE password masked.

type InterfaceUpdate

type InterfaceUpdate struct {
	Enabled  *bool
	Protocol *string
	Address  *netip.Prefix
	Gateway  *netip.Addr
	DNS      *netip.Addr
	Username *string
	Password *string
}

InterfaceUpdate lists the interface settings to change; nil fields are left as they are. Addresses must be IPv4.

type UPnP

type UPnP struct {
	Enabled bool `json:"enabled"`
	NATPMP  bool `json:"nat_pmp_enabled"`
	Port    int  `json:"port"`
}

UPnP is the UPnP and NAT-PMP port mapping service configuration.

func GetUPnP

func GetUPnP(ctx context.Context, c *amplifi.Client) (*UPnP, error)

GetUPnP fetches the UPnP/NAT-PMP configuration.

type UPnPUpdate

type UPnPUpdate struct {
	Enabled *bool
	NATPMP  *bool
	Port    *int
}

UPnPUpdate lists the UPnP settings to change; nil fields are left as they are.

Jump to

Keyboard shortcuts

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