func()

in pkg/metrics/collector/pod_ip_metrics.go [320:341]


func (c *podIPMetricsCollector) countIPsFromRange(subnet *net.IPNet) (uint64, error) {
	ones, bits := subnet.Mask.Size()
	if bits <= ones {
		return 0, fmt.Errorf("invalid subnet mask: %v", subnet.Mask)
	}
	// this checks that we are not overflowing an int64
	if bits-ones >= 64 {
		return math.MaxUint64, nil
	}
	count := uint64(1) << uint(bits-ones)
	count--
	if subnet.IP.To4() != nil {
		// Don't use the IPv4 network's broadcast address
		if count == 0 {
			return 0, fmt.Errorf("subnet includes only the network and broadcast addresses")
		}
		count--
	} else if count == 0 {
		return 0, fmt.Errorf("subnet includes only the network address")
	}
	return count, nil
}