OpenNHP/opennhp · error

invalid IP address

Error message

invalid IP address: %s

What it means

parseIP in nhp/utils/ebpf/ebpf.go validates an IP string with net.ParseIP before converting it to a uint32 for eBPF map rules. When the string is not a parseable IP address (nil result), the function logs and returns this error. Callers building firewall-style eBPF rules from user-supplied address strings will abort rule creation.

Solutions

  1. Print the offending string and validate it with net.ParseIP before calling the eBPF rule API
  2. Correct the config value to a valid literal IPv4 address
  3. Trim whitespace and strip any /prefix CIDR suffix before passing
  4. Resolve hostnames to IPs with net.LookupHost first if a DNS name is intended

Example fix

// before
AddEbpfRuleForSrcDst("10.0.0.256", "192.168.1.10", ...)
// after
if net.ParseIP(strings.TrimSpace(src)) == nil { return fmt.Errorf("bad src ip %q", src) }
AddEbpfRuleForSrcDst("10.0.0.1", "192.168.1.10", ...)
Defensive patterns

Strategy: validation

Validate before calling

func validIPv4(s string) bool { ip := net.ParseIP(strings.TrimSpace(s)); return ip != nil && ip.To4() != nil }
if !validIPv4(src) { return fmt.Errorf("invalid src ip: %q", src) }

Try / catch

if err != nil { return fmt.Errorf("ebpf rule rejected: %w", err) }

Prevention

When it happens

Trigger: Calling AddEbpfRuleForSrcDstPortProto, AddEbpfRuleForSrcDst, AddEbpfRuleForSrcDestPort, AddEbpfIcmpRuleForSrcDst, or AddEbpfRuleForSrcDestPortList with a src or dst string that net.ParseIP cannot parse (e.g. '999.1.1.1', '10.0.0.256', 'host.local', or an empty string).

Common situations: Config file (resource.toml / rule definitions) contains a hostname instead of a literal IP; a template variable was left unexpanded; trailing whitespace or CIDR suffix ('10.0.0.1/24') passed where a bare IP is expected; IPv6 address supplied but later rejected by the IPv4 check.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of OpenNHP/opennhp@6e04ca5ff0 (2026-09-07). Data as JSON: /api/errors/735f029ec4989ca4. Report an issue: GitHub.

Appendix: source

Thrown at nhp/utils/ebpf/ebpf.go:470

		err = AddEbpfRuleForProtocolPort(protocol, dstPort, TtlSec64)
		if err != nil {
			log.Error("failed add ebpf protocol: %s dst port: %d", params.Protocol, params.DstPort)
			return err
		}

	default:
		return fmt.Errorf("unsupported map type: %d", mapType)
	}

	return nil
}

// Parse the IP address
func parseIP(ipStr string) (uint32, error) {
	ip := net.ParseIP(ipStr)
	if ip == nil {
		log.Error("invalid IP address: %s", ipStr)
		return 0, fmt.Errorf("invalid IP address: %s", ipStr)
	}
	ip = ip.To4()
	if ip == nil {
		log.Error("only IPv4 addresses are supported: %s", ipStr)
		return 0, fmt.Errorf("only IPv4 addresses are supported: %s", ipStr)
	}
	return binary.LittleEndian.Uint32(ip), nil
}

// Parse the port
func parsePort(portStr string) (uint16, error) {
	port, err := strconv.ParseUint(portStr, 10, 16)
	if err != nil {
		return 0, err
	}
	return binary.LittleEndian.Uint16([]byte{byte(port >> 8), byte(port & 0xFF)}), nil
}

View on GitHub (pinned to 6e04ca5ff0)