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 ¶
- func GetQoS(ctx context.Context, c *amplifi.Client) (map[string]any, error)
- func SetQoS(ctx context.Context, c *amplifi.Client, cfg map[string]any) error
- func UpdateConfig(ctx context.Context, c *amplifi.Client, u ConfigUpdate) error
- func UpdateInterface(ctx context.Context, c *amplifi.Client, ifname string, u InterfaceUpdate) error
- func UpdateUPnP(ctx context.Context, c *amplifi.Client, u UPnPUpdate) error
- type Config
- type ConfigUpdate
- type Interface
- type InterfaceUpdate
- type UPnP
- type UPnPUpdate
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetQoS ¶
SetQoS replaces the QoS configuration. cfg is sent as JSON and should have the shape GetQoS returns.
func UpdateConfig ¶
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 ¶
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.
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 ¶
Interfaces lists the unit's logical network interfaces, sorted by name.
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.
type UPnPUpdate ¶
UPnPUpdate lists the UPnP settings to change; nil fields are left as they are.