lints/lint_subject_contains_reserved_arpa_ip.go
func lintReversedIPAddress(name string, ipv6 bool) error {
	numRequiredLabels := rdnsIPv4Labels
	zoneSuffix := rdnsIPv4Suffix

	if ipv6 {
		numRequiredLabels = rdnsIPv6Labels
		zoneSuffix = rdnsIPv6Suffix
	}

	// Strip off the zone suffix to get only the reversed IP address
	ipName := strings.TrimSuffix(name, zoneSuffix)

	// A well encoded IPv4 or IPv6 reverse DNS name will have the correct number
	// of labels to express the address. If there isn't the right number of labels
	// a separate `lint_subject_contains_malformed_arpa_ip.go` linter will flag it
	// as a warning. This linter is specifically concerned with well formed rDNS
	// that specifies a reserved IP.
	ipLabels := strings.Split(ipName, ".")
	if len(ipLabels) != numRequiredLabels {
		return nil
	}

	// Reverse the IP labels and try to parse an IP address
	var ip net.IP
	if ipv6 {
		ip = reversedLabelsToIPv6(ipLabels)
	} else {
		ip = reversedLabelsToIPv4(ipLabels)
	}
	// If the result isn't an IP at all assume there is no problem - leave
	// `lint_subject_contains_malformed_arpa_ip` to flag it as a warning.
	if ip == nil {
		return nil
	}

	if !ipv6 && ip.To4() == nil {
		// If we weren't expecting IPv6 and got it, that's a problem
		return fmt.Errorf(
			"the first %d labels of name %q parsed as a reversed IPv6 address but is "+
				"in the %q IPv4 reverse DNS zone.",
			numRequiredLabels, name, rdnsIPv4Suffix)
	} else if ipv6 && ip.To4() != nil {
		// If we were expecting IPv6 and got an IPv4 address, that's a problem
		return fmt.Errorf(
			"the first %d labels of name %q parsed as a reversed IPv4 address but is "+
				"in the %q IPv4 reverse DNS zone.",
			numRequiredLabels, name, rdnsIPv6Suffix)
	}

	// If the IP address is in an IANA reserved space, that's a problem.
	if util.IsIANAReserved(ip) {
		return fmt.Errorf(
			"the first %d labels of name %q parsed as a reversed IP address in "+
				"an IANA reserved IP space.",
			numRequiredLabels, name)
	}

	return nil
}
func lintReversedIPAddress(name string, ipv6 bool) error {
	numRequiredLabels := rdnsIPv4Labels
	zoneSuffix := rdnsIPv4Suffix

	if ipv6 {
		numRequiredLabels = rdnsIPv6Labels
		zoneSuffix = rdnsIPv6Suffix
	}

	// Strip off the zone suffix to get only the reversed IP address
	ipName := strings.TrimSuffix(name, zoneSuffix)

	// A well encoded IPv4 or IPv6 reverse DNS name will have the correct number
	// of labels to express the address. If there isn't the right number of labels
	// a separate `lint_subject_contains_malformed_arpa_ip.go` linter will flag it
	// as a warning. This linter is specifically concerned with well formed rDNS
	// that specifies a reserved IP.
	ipLabels := strings.Split(ipName, ".")
	if len(ipLabels) != numRequiredLabels {
		return nil
	}

	// Reverse the IP labels and try to parse an IP address
	var ip net.IP
	if ipv6 {
		ip = reversedLabelsToIPv6(ipLabels)
	} else {
		ip = reversedLabelsToIPv4(ipLabels)
	}
	// If the result isn't an IP at all assume there is no problem - leave
	// `lint_subject_contains_malformed_arpa_ip` to flag it as a warning.
	if ip == nil {
		return nil
	}

	if !ipv6 && ip.To4() == nil {
		// If we weren't expecting IPv6 and got it, that's a problem
		return fmt.Errorf(
			"the first %d labels of name %q parsed as a reversed IPv6 address but is "+
				"in the %q IPv4 reverse DNS zone.",
			numRequiredLabels, name, rdnsIPv4Suffix)
	} else if ipv6 && ip.To4() != nil {
		// If we were expecting IPv6 and got an IPv4 address, that's a problem
		return fmt.Errorf(
			"the first %d labels of name %q parsed as a reversed IPv4 address but is "+
				"in the %q IPv4 reverse DNS zone.",
			numRequiredLabels, name, rdnsIPv6Suffix)
	}

	// If the IP address is in an IANA reserved space, that's a problem.
	if util.IsIANAReserved(ip) {
		return fmt.Errorf(
			"the first %d labels of name %q parsed as a reversed IP address in "+
				"an IANA reserved IP space.",
			numRequiredLabels, name)
	}

	return nil
}
// lintReversedIPAddress lints the given name as either a reversed IPv4 or IPv6
// address under the respective ARPA zone based on the address class. An error
// is returned if:
//
// 1. The IP address labels parse as an IP of the wrong address class for the
//    arpa suffix the name is using.
// 2. The IP address is within an IANA reserved range.