Documentation ¶
Index ¶
- func OverlappingSubnets(snet1, snet2 string) (bool, error)
- type IPRange
- type IPRangeAllocator
- func (a *IPRangeAllocator) Allocate() net.IP
- func (a *IPRangeAllocator) IPRange() *IPRange
- func (a *IPRangeAllocator) Release(ip net.IP)
- func (a *IPRangeAllocator) Remaining() int64
- func (a *IPRangeAllocator) Reserve(ip net.IP)
- func (a *IPRangeAllocator) Size() int64
- func (a *IPRangeAllocator) Subtract(iprange *IPRange)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func OverlappingSubnets ¶
function takes two subnets (CIDR blocks)as input and determines if they overlap. this differs from the above Overlaps() in that we only specify subnets and not ranges; for example: 10.0.0.0/16 and 10.0.0.0/8 are subnets and they overlap. See TestIPRangeOverlappingSubnets for more examples. NOTE/TODO: only supports IPv4
Types ¶
type IPRange ¶
IPRange is used to represent a range of IP addresses, such as "192.168.1.1-100". It can be used to parse string representations and check if other provided IPs are within the given range. It can also be used with other utilies to handle allocation of IPs from the provided range.
func ParseIPRange ¶
ParseIPRange creates an IPRange object based on the provided string representing the range. The string for a range is in the form of "192.168.1.1-100", to specify a range of IPs from 192.168.1.1 to 192.168.1.100. The string can also contain a network mask, such as "192.168.1.1-100/24". Strings can span over multiple octets, such as "192.168.1.1-2.1", and a range can also be just a single IP. An error will be returned if it fails to parse the IPs, if the end IP isn't after the start IP, and if a network mask is given, it will error if the mask is in valid, or the range does not fall within the bounds of the provided mask.
type IPRangeAllocator ¶
type IPRangeAllocator struct {
// contains filtered or unexported fields
}
IPRangeAllocator can be used to allocate IP addresses from the provided range.
func NewAllocator ¶
func NewAllocator(ipr *IPRange) *IPRangeAllocator
NewAllocator creates a new IPRangeAllocator for the provided IPRange.
func (*IPRangeAllocator) Allocate ¶
func (a *IPRangeAllocator) Allocate() net.IP
Allocate can be used to allocate a new IP address within the provided range. It will ensure that it is unique. If the allocator has no additional IP addresses available, then it will return nil.
func (*IPRangeAllocator) IPRange ¶
func (a *IPRangeAllocator) IPRange() *IPRange
IPRange returns a copy of the IPRange provided to the allocator.
func (*IPRangeAllocator) Release ¶
func (a *IPRangeAllocator) Release(ip net.IP)
Release can be used to release an IP address that had previously been allocated or reserved.
func (*IPRangeAllocator) Remaining ¶
func (a *IPRangeAllocator) Remaining() int64
Remaining returns the number of remaining IP addresses within the provided range that have not been already allocated.
func (*IPRangeAllocator) Reserve ¶
func (a *IPRangeAllocator) Reserve(ip net.IP)
Reserve allows reserving a specific IP address within the specified range to ensure it is not allocated.
func (*IPRangeAllocator) Size ¶
func (a *IPRangeAllocator) Size() int64
Size returns the size of the allowable IP addresses specified by the range.
func (*IPRangeAllocator) Subtract ¶
func (a *IPRangeAllocator) Subtract(iprange *IPRange)
Subtract marks all of the IPs from another IPRange as reserved in the current allocator.