{"record":{"id":"667f1c43747dd806","repo":"OpenNHP/opennhp","slug":"only-ipv4-addresses-are-supported-s","errorCode":null,"errorMessage":"only IPv4 addresses are supported: %s","messagePattern":"only IPv4 addresses are supported: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nhp/utils/ebpf/ebpf.go","lineNumber":475,"sourceCode":"\n\tdefault:\n\t\treturn fmt.Errorf(\"unsupported map type: %d\", mapType)\n\t}\n\n\treturn nil\n}\n\n// Parse the IP address\nfunc parseIP(ipStr string) (uint32, error) {\n\tip := net.ParseIP(ipStr)\n\tif ip == nil {\n\t\tlog.Error(\"invalid IP address: %s\", ipStr)\n\t\treturn 0, fmt.Errorf(\"invalid IP address: %s\", ipStr)\n\t}\n\tip = ip.To4()\n\tif ip == nil {\n\t\tlog.Error(\"only IPv4 addresses are supported: %s\", ipStr)\n\t\treturn 0, fmt.Errorf(\"only IPv4 addresses are supported: %s\", ipStr)\n\t}\n\treturn binary.LittleEndian.Uint32(ip), nil\n}\n\n// Parse the port\nfunc parsePort(portStr string) (uint16, error) {\n\tport, err := strconv.ParseUint(portStr, 10, 16)\n\tif err != nil {\n\t\treturn 0, err\n\t}\n\treturn binary.LittleEndian.Uint16([]byte{byte(port >> 8), byte(port & 0xFF)}), nil\n}\n","sourceCodeStart":457,"sourceCodeEnd":488,"githubUrl":"https://github.com/OpenNHP/opennhp/blob/6e04ca5ff03222a699c24205cd4bf8fee9af7ffe/nhp/utils/ebpf/ebpf.go#L457-L488","documentation":"After net.ParseIP succeeds, parseIP converts to 4-byte form with ip.To4(). IPv6 addresses (and any value that is not IPv4) yield nil from To4, so the function rejects them because the eBPF rule maps store 32-bit IPv4 keys only. The address must be a literal IPv4 address.","triggerScenarios":"Passing an IPv6 literal like '::1' or '2001:db8::1' (or an IPv4-mapped form that the map format cannot accept) to any of the AddEbpf* rule functions; passing a hostname that ParseIP resolves as IPv6 only.","commonSituations":"Dual-stack environments where configured endpoints have AAAA records; users copying IPv6 addresses from `ip -6` output; configs written for IPv6-only clusters.","solutions":["Supply a literal IPv4 address instead of IPv6","If dual-stack is required, extend the eBPF map/key structs to v6 or maintain a separate v4/v6 rule path","Pre-validate with `ip := net.ParseIP(s); ip.To4() != nil` and surface a clear config error"],"exampleFix":"// before\nAddEbpfRuleForSrcDst(\"::1\", \"10.0.0.1\", ...)\n// after\nAddEbpfRuleForSrcDst(\"127.0.0.1\", \"10.0.0.1\", ...)","handlingStrategy":"validation","validationCode":"func isIPv4(s string) bool { ip := net.ParseIP(s); return ip != nil && ip.To4() != nil }","typeGuard":null,"tryCatchPattern":"if err := addRule(...); err != nil { if strings.Contains(err.Error(), \"only IPv4\") { /* convert or skip */ } }","preventionTips":["Decide dual-stack strategy before using the eBPF rule API","Test configs containing IPv6 addresses in CI","Document that eBPF rules are IPv4-only"],"tags":["ebpf","ipv6","unsupported","networking"],"backgroundTag":"unsupported-operation","analyzedSha":"6e04ca5ff03222a699c24205cd4bf8fee9af7ffe","analyzedAt":"2026-09-07T15:44:59.941Z","contentChangedAt":"2026-09-07T15:44:59.941Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}