netbirdio/netbird · error

add inbound DNAT

Error message

add inbound DNAT: %w

What it means

A sentinel wrap of firewall.ErrIPv6NotInitialized: AddInboundDNAT was called with an IPv6 local address, but the manager has no IPv6 router initialized (the peer has no v6 capability or v6 init failed). The request is rejected rather than silently applied to the v4 path, so callers can distinguish a capability mismatch from a kernel error.

Solutions

  1. Enable IPv6 in the overlay before adding v6 inbound DNAT
  2. Use an IPv4 local address for the redirect
  3. Check manager initialization flags before issuing v6 rules
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at client/firewall/nftables/manager_linux.go:626 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/77a72c4b60d6ebb6. Report an issue: GitHub.

Appendix: source

Thrown at client/firewall/nftables/manager_linux.go:626

	}

	if m.hasIPv6() && len(v6Prefixes) > 0 {
		if err := m.router6.UpdateSet(set, v6Prefixes); err != nil {
			return fmt.Errorf("update v6 set: %w", err)
		}
	}

	return nil
}

// AddInboundDNAT adds an inbound DNAT rule redirecting traffic from NetBird peers to local services.
func (m *Manager) AddInboundDNAT(localAddr netip.Addr, protocol firewall.Protocol, originalPort, translatedPort uint16) error {
	m.mutex.Lock()
	defer m.mutex.Unlock()

	if localAddr.Is6() {
		if !m.hasIPv6() {
			return fmt.Errorf("add inbound DNAT: %w", firewall.ErrIPv6NotInitialized)
		}
		return m.router6.AddInboundDNAT(localAddr, protocol, originalPort, translatedPort)
	}
	return m.router.AddInboundDNAT(localAddr, protocol, originalPort, translatedPort)
}

// RemoveInboundDNAT removes an inbound DNAT rule.
func (m *Manager) RemoveInboundDNAT(localAddr netip.Addr, protocol firewall.Protocol, originalPort, translatedPort uint16) error {
	m.mutex.Lock()
	defer m.mutex.Unlock()

	if localAddr.Is6() {
		if !m.hasIPv6() {
			return fmt.Errorf("remove inbound DNAT: %w", firewall.ErrIPv6NotInitialized)
		}
		return m.router6.RemoveInboundDNAT(localAddr, protocol, originalPort, translatedPort)
	}
	return m.router.RemoveInboundDNAT(localAddr, protocol, originalPort, translatedPort)

View on GitHub (pinned to 93e97f4bf1)