{"record":{"id":"3511c51087c40d8d","repo":"cilium/cilium","slug":"invalid-gateway-address-s","errorCode":null,"errorMessage":"invalid gateway address: %s","messagePattern":"invalid gateway address: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugins/cilium-cni/cmd/cmd.go","lineNumber":439,"sourceCode":"\t\tif state.HostAddr != nil {\n\t\t\tif routes, err = connector.IPv4Routes(state.HostAddr, mtu); err != nil {\n\t\t\t\treturn nil, nil, err\n\t\t\t}\n\t\t\tstate.IP4routes = append(state.IP4routes, routes...)\n\t\t\tgw = connector.IPv4Gateway(state.HostAddr)\n\t\t}\n\t}\n\n\trt := make([]*cniTypes.Route, 0, len(routes))\n\tfor _, r := range routes {\n\t\trt = append(rt, newCNIRoute(r))\n\t}\n\n\tvar gwIP net.IP\n\tif gw != \"\" {\n\t\tgwIP = net.ParseIP(gw)\n\t\tif gwIP == nil {\n\t\t\treturn nil, nil, fmt.Errorf(\"invalid gateway address: %s\", gw)\n\t\t}\n\t}\n\n\treturn &cniTypesV1.IPConfig{\n\t\tAddress: *netipx.AddrIPNet(ip),\n\t\tGateway: gwIP,\n\t}, rt, nil\n}\n\nfunc (cmd *Cmd) setupLogging(n *types.NetConf) error {\n\tf := n.LogFormat\n\tif f == \"\" {\n\t\tf = string(logging.DefaultLogFormatTimestamp)\n\t}\n\tlogOptions := logging.LogOptions{\n\t\tlogging.FormatOpt: f,\n\t\tlogging.WriterOpt: logging.StdErrOpt,\n\t}","sourceCodeStart":421,"sourceCodeEnd":457,"githubUrl":"https://github.com/cilium/cilium/blob/ac7b90affa4baf0642e6685319d56907b3a73a6d/plugins/cilium-cni/cmd/cmd.go#L421-L457","documentation":"prepareIP builds the CNI IPConfig for an allocated IP. If the caller supplied a non-empty gateway string that net.ParseIP cannot parse, the plugin rejects it with 'invalid gateway address'. This is a configuration/data validation error, not a kernel error.","triggerScenarios":"prepareIP is called with a gw string that is non-empty but not a valid IP literal (net.ParseIP returns nil) during CNI ADD.","commonSituations":"Custom CNI config with a malformed gateway (hostname, CIDR with prefix, trailing whitespace, IPv4-mapped typos), or a buggy IPAM/ciliate agent response carrying a bad .IPAM.gateway value.","solutions":["Inspect the CNI config / IPAM response and correct the gateway to a valid dotted-quad or IPv6 literal","Remove the custom gateway field so Cilium derives it from the node CIDR","Check cilium-agent logs for the IPAMResponse being handed to the plugin","If from a custom IPAM plugin, fix its gateway formatting (no prefix length, no hostnames)"],"exampleFix":"// before (CNI config)\n\"gateway\": \"10.0.0.1/24\"\n// after\n\"gateway\": \"10.0.0.1\"","handlingStrategy":"validation","validationCode":"if gw != \"\" && net.ParseIP(strings.TrimSpace(gw)) == nil {\n    return fmt.Errorf(\"gateway %q is not a valid IP literal\", gw)\n}","typeGuard":null,"tryCatchPattern":"ipCfg, routes, rules, err := prepareIP(ipam, ...)\nif err != nil && strings.Contains(err.Error(), \"invalid gateway address\") {\n    return fmt.Errorf(\"fix gateway in CNI/IPAM config: %w\", err)\n}","preventionTips":["Never put hostnames or CIDR notation in gateway fields","Prefer letting Cilium derive the gateway from the node CIDR","Lint CNI configs in CI before cluster rollout"],"tags":["cilium","cni","validation","configuration","ipam"],"backgroundTag":"invalid-ip-address","analyzedSha":"ac7b90affa4baf0642e6685319d56907b3a73a6d","analyzedAt":"2026-08-31T18:27:15.868Z","schemaVersion":2},"datasetVersion":"2026-08-31T22:30:34.772Z"}