func()

in pkg/dns/config/config.go [91:119]


func (config *Config) validateStubDomains() error {
	for domain, nsList := range config.StubDomains {
		if len(validation.IsDNS1123Subdomain(domain)) != 0 {
			return fmt.Errorf("invalid domain name: %q", domain)
		}

		for _, ns := range nsList {
			host, port, err := net.SplitHostPort(ns)
			// it can error if the port is missing
			// or if there are too many colons (invalid host)
			// so we assume that ns is passed without port
			// and fail later in validation if the host was invalid
			if err != nil {
				host = ns
			}
			// Validate port if specified
			if port != "" {
				if _, err := strconv.ParseUint(port, 10, 16); err != nil {
					return fmt.Errorf("invalid nameserver: %q", ns)
				}
			}
			if len(validation.IsValidIP(host)) > 0 && len(validation.IsDNS1123Subdomain(ns)) > 0 {
				return fmt.Errorf("invalid nameserver: %q", ns)
			}
		}
	}

	return nil
}