{"record":{"id":"5b765d1625cf7c21","repo":"cilium/cilium","slug":"interface-name-contains-invalid-characters-q-al","errorCode":null,"errorMessage":"interface name contains invalid characters: %q (allowed: a-z A-Z 0-9 . _ -)","messagePattern":"interface name contains invalid characters: %q \\(allowed: a-z A-Z 0-9 \\. _ -\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/networkdriver/types/types.go","lineNumber":86,"sourceCode":")\n\n// ValidateInterfaceName validates an interface name according to Linux rules\nfunc ValidateInterfaceName(name string) error {\n\t// Empty name is valid (means no custom rename)\n\tif name == \"\" {\n\t\treturn nil\n\t}\n\n\t// Check length limit (Linux IFNAMSIZ - 1)\n\tif len(name) > MaxInterfaceNameLength {\n\t\treturn fmt.Errorf(\n\t\t\t\"interface name too long: %q (%d chars, max %d)\",\n\t\t\tname, len(name), MaxInterfaceNameLength)\n\t}\n\n\t// Check for valid characters\n\tif !validIfNameRegex.MatchString(name) {\n\t\treturn fmt.Errorf(\n\t\t\t\"interface name contains invalid characters: %q (allowed: a-z A-Z 0-9 . _ -)\",\n\t\t\tname)\n\t}\n\n\t// Check for reserved names\n\tif name == \"lo\" {\n\t\treturn fmt.Errorf(\"interface name %q is reserved (loopback)\", name)\n\t}\n\n\tif len(name) >= 7 && name[:7] == \"cilium_\" {\n\t\treturn fmt.Errorf(\"interface name %q is reserved (cilium_ prefix)\", name)\n\t}\n\n\treturn nil\n}\n\ntype DeviceManagerType int\n","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/cilium/cilium/blob/ac7b90affa4baf0642e6685319d56907b3a73a6d/pkg/networkdriver/types/types.go#L68-L104","documentation":"ValidateInterfaceName checks names against validIfNameRegex, which permits only letters, digits, dots, underscores, and hyphens. This error means the requested interface name contains characters the kernel or the library disallows (e.g. '/', ':', spaces, '@').","triggerScenarios":"Calling ValidateInterfaceName (via any name-accepting API) with a name containing characters outside [a-zA-Z0-9._-], such as 'eth 0', 'eth:0', or a name with a slash.","commonSituations":"Using VLAN-style 'eth0.100' style with extra separators like ':' for aliases; accidental whitespace from untrimmed config values; templated names interpolating un-sanitized identifiers.","solutions":["Sanitize the interface name: replace invalid characters with '-' or '_' before calling.","Trim whitespace from configuration values that supply the name.","Validate generated names with a regex like ^[a-zA-Z0-9._-]+$ in your own generator."],"exampleFix":"// before\nname := \"eth0:alias\" // ':' invalid\n// after\nname := \"eth0-alias\"\nif !regexp.MustCompile(`^[a-zA-Z0-9._-]+$`).MatchString(name) { /* sanitize */ }","handlingStrategy":"validation","validationCode":"var validIfName = regexp.MustCompile(`^[a-zA-Z0-9._-]+$`)\nname = strings.TrimSpace(name)\nif !validIfName.MatchString(name) {\n    name = validIfName.ReplaceAllString(name, \"_\") // or reject\n}","typeGuard":"func isValidIfName(name string) bool {\n    return regexp.MustCompile(`^[a-zA-Z0-9._-]+$`).MatchString(name)\n}","tryCatchPattern":"if err := types.ValidateInterfaceName(name); err != nil {\n    if strings.Contains(err.Error(), \"invalid characters\") {\n        name = sanitize(name)\n        return types.ValidateInterfaceName(name)\n    }\n    return err\n}","preventionTips":["Trim whitespace on all config inputs feeding interface names.","Sanitize interpolated identifiers (pod IDs, UUIDs) before composing names.","Add a shared sanitize/validate helper at every name-generation site."],"tags":["network","interface-name","validation"],"backgroundTag":"interface-name-invalid-characters","analyzedSha":"ac7b90affa4baf0642e6685319d56907b3a73a6d","analyzedAt":"2026-08-31T18:27:15.868Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}