iprange

package
v0.0.0-...-7a50bc8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 22, 2018 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func OverlappingSubnets

func OverlappingSubnets(snet1, snet2 string) (bool, error)

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

type IPRange struct {
	Start net.IP
	End   net.IP
	Mask  net.IPMask
}

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

func ParseIPRange(s string) (*IPRange, error)

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.

func (*IPRange) Contains

func (ipr *IPRange) Contains(ip net.IP) bool

Contains returns whether or not the given IP address is within the specified IPRange.

func (*IPRange) Overlaps

func (ipr *IPRange) Overlaps(o *IPRange) bool

Overlaps checks whether another IPRange instance has an overlap in IPs with the current range. If will return true if there is any cross section between the two ranges.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL