netbirdio/netbird · error

invalid port

Error message

invalid port: %w

What it means

A firewall rule carrying the legacy single-port string (from an older management server) contains a value strconv.Atoi cannot parse, so no firewall.Port can be built. The rule is skipped with this error rather than installed with a wrong port, and processing of the remaining rules continues.

Solutions

  1. Upgrade management to send structured PortInfo
  2. Tolerate empty port fields for protocol ALL
  3. Validate legacy port strings before parsing
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at client/internal/acl/manager.go:304 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of netbirdio/netbird@93e97f4bf1 (2026-08-16). Data as JSON: /api/errors/7b92ae35d0e894d4. Report an issue: GitHub.

Appendix: source

Thrown at client/internal/acl/manager.go:304

	protocol, err := convertToFirewallProtocol(r.Protocol)
	if err != nil {
		return "", nil, fmt.Errorf("skipping firewall rule: %s", err)
	}

	action, err := convertFirewallAction(r.Action)
	if err != nil {
		return "", nil, fmt.Errorf("skipping firewall rule: %s", err)
	}

	var port *firewall.Port
	if !portInfoEmpty(r.PortInfo) {
		port = convertPortInfo(r.PortInfo)
	} else if r.Port != "" {
		// old version of management, single port
		value, err := strconv.Atoi(r.Port)
		if err != nil {
			return "", nil, fmt.Errorf("invalid port: %w", err)
		}
		port = &firewall.Port{
			Values: []uint16{uint16(value)},
		}
	}

	ruleID := d.getPeerRuleID(ip, protocol, int(r.Direction), port, action)
	if rulesPair, ok := d.peerRulesPairs[ruleID]; ok {
		return ruleID, rulesPair, nil
	}

	var rules []firewall.Rule
	switch r.Direction {
	case mgmProto.RuleDirection_IN:
		rules, err = d.addInRules(r.PolicyID, ip, protocol, port, action, ipsetName)
	case mgmProto.RuleDirection_OUT:
		if d.firewall.IsStateful() {
			return "", nil, nil

View on GitHub (pinned to 93e97f4bf1)