portforward

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: 10 Imported by: 0

Documentation

Overview

Package portforward reads and changes a unit's port forwarding rules.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddRule

func AddRule(ctx context.Context, c *amplifi.Client, r Rule) (int, error)

AddRule adds rule r and returns its ID. When r.ID is 0 the next free ID is used.

func DeleteRules

func DeleteRules(ctx context.Context, c *amplifi.Client, ids ...int) error

DeleteRules deletes rules by ID.

func UpdateRule

func UpdateRule(ctx context.Context, c *amplifi.Client, id int, u RuleUpdate) error

UpdateRule changes rule id. It reads all rules, applies u to that one and writes them all back with SetPortForwardingConfig.

Types

type Mapping

type Mapping struct {
	ID       int      `json:"id"`
	Protocol Protocol `json:"protocol"`
	WANPort  int      `json:"wan_port"`
	LANPort  int      `json:"lan_port"`
	WANCount int      `json:"wan_count"`
	LANCount int      `json:"lan_count"`
}

Mapping is one port range of a forwarding rule. WANCount and LANCount are the number of ports in each range (the router's *PortRangeLength); 0 and 1 both mean a single port. LANPort 0 means the same as WANPort.

type Protocol

type Protocol int

Protocol is the IP protocol of a mapping, by its IP protocol number.

const (
	TCP Protocol = 6
	UDP Protocol = 17
)

Protocols of a mapping.

func ParseProtocol

func ParseProtocol(s string) (Protocol, error)

ParseProtocol parses "tcp" or "udp".

func (Protocol) MarshalText

func (p Protocol) MarshalText() ([]byte, error)

MarshalText renders the protocol by name.

func (Protocol) String

func (p Protocol) String() string

String returns "tcp" or "udp", or "#N" for another protocol number.

type Rule

type Rule struct {
	ID       int        `json:"id"`
	Name     string     `json:"name"`
	Enabled  bool       `json:"enabled"`
	LANIP    netip.Addr `json:"lan_ip"`
	Mappings []Mapping  `json:"mappings"`
}

Rule is one port forwarding rule (PortForwardingRule). A rule forwarding both TCP and UDP has one mapping per protocol.

func Rules

func Rules(ctx context.Context, c *amplifi.Client) ([]Rule, error)

Rules lists the port forwarding rules, sorted by ID.

type RuleUpdate

type RuleUpdate struct {
	Name     *string
	Enabled  *bool
	LANIP    *netip.Addr
	Mappings []Mapping
}

RuleUpdate lists the rule fields to change; nil fields are left as they are. A non-nil Mappings replaces all the rule's mappings.

Jump to

Keyboard shortcuts

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