Documentation ¶
Overview ¶
Package subnet contains functions for finding available subnets
Index ¶
- func CoveringCIDRs(ips []net.IP) []*net.IPNet
- func Covers(a, b *net.IPNet) bool
- func Equal(a, b *net.IPNet) bool
- func IsHalfOfDefault(n *net.IPNet) bool
- func IsZeroMask(n *net.IPNet) bool
- func Overlaps(a, b *net.IPNet) bool
- func Partition(subnets []*net.IPNet, filter func(int, *net.IPNet) bool) (matched, notMatched []*net.IPNet)
- func RandomIPv4Subnet(mask net.IPMask, avoid []*net.IPNet) (*net.IPNet, error)
- func Unique(subnets []*net.IPNet) []*net.IPNet
- type Bitfield256
- func (b *Bitfield256) ClearBit(bv byte)
- func (b *Bitfield256) Equals(other *Bitfield256) bool
- func (b *Bitfield256) GetBit(bv byte) bool
- func (b *Bitfield256) Mask() (ones int, value byte)
- func (b *Bitfield256) OnesCount() (l int)
- func (b *Bitfield256) SetBit(bv byte)
- func (b *Bitfield256) String() string
- func (b *Bitfield256) ToSlice() []byte
- type Set
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CoveringCIDRs ¶ added in v2.3.2
CoveringCIDRs returns the ip networks needed to cover the given IPs with as big mask as possible for each subnet. The analysis starts by finding all subnets using a 16-bit mask for IPv4 and a 64 bit mask for IPv6 addresses. Once the subnets are established, the mask for each one will be increased to the maximum value that still masks all IPs that it was created for.
Note: A similar method exists in Telepresence 1, but this method was not compared to it when written.
func Covers ¶ added in v2.3.2
Covers answers the question if network range a contains the full network range b.
func IsHalfOfDefault ¶ added in v2.14.0
IsHalfOfDefault route returns true if the given subnet covers half the address space with a /1 mask.
func IsZeroMask ¶ added in v2.14.0
func Overlaps ¶ added in v2.13.0
Overlaps answers the question if there is an overlap between network range a and b.
func Partition ¶ added in v2.3.2
func Partition(subnets []*net.IPNet, filter func(int, *net.IPNet) bool) (matched, notMatched []*net.IPNet)
Partition returns two slices, the first containing the subnets for which the filter evaluates to true, the second containing the rest.
func RandomIPv4Subnet ¶ added in v2.13.0
RandomIPv4Subnet finds a random free subnet using the given mask. A subnet is considered free if it doesn't overlap with any of the subnets returned by the net.InterfaceAddrs function or with any of the subnets provided in the avoid parameter. The returned subnet will be a private IPv4 subnet in either class C, B, or A range, and the search for a free subnet uses that order. See https://en.wikipedia.org/wiki/Private_network for more info about private subnets.
Types ¶
type Bitfield256 ¶ added in v2.3.2
type Bitfield256 [4]uint64
Bitfield256 represents 0 - 255 unique bytes.
func (*Bitfield256) ClearBit ¶ added in v2.3.2
func (b *Bitfield256) ClearBit(bv byte)
ClearBit clears the 1<<bv bit of the bitfield to 0.
func (*Bitfield256) Equals ¶ added in v2.3.2
func (b *Bitfield256) Equals(other *Bitfield256) bool
Equals returns true if this Bitfield256 equals the argument.
func (*Bitfield256) GetBit ¶ added in v2.3.2
func (b *Bitfield256) GetBit(bv byte) bool
GetBit returns the value of the 1<<bv bit of the bitfield (0 is false, 1 is true).
func (*Bitfield256) Mask ¶ added in v2.3.2
func (b *Bitfield256) Mask() (ones int, value byte)
Mask returns how many bits, from left to right, that have the same value for all bytes represented by this Bitfield256 and a byte containing the value of those bits.
func (*Bitfield256) OnesCount ¶ added in v2.3.2
func (b *Bitfield256) OnesCount() (l int)
OnesCount returns the number of 1 bits in the bitfield.
func (*Bitfield256) SetBit ¶ added in v2.3.2
func (b *Bitfield256) SetBit(bv byte)
SetBit sets the 1<<bv bit of the bitfield to 1.
func (*Bitfield256) String ¶ added in v2.3.2
func (b *Bitfield256) String() string
String prints the hexadecimal representation of the bits.
func (*Bitfield256) ToSlice ¶ added in v2.3.2
func (b *Bitfield256) ToSlice() []byte
ToSlice returns an ordered slice of all bytes in this Bitfield256.
type Set ¶ added in v2.4.4
type Set map[setKey]struct{}
Set represents a unique unordered set of subnets.
func (Set) Add ¶ added in v2.4.4
Add adds a subnet to this set unless it doesn't already exist. Returns true if the subnet was added, false otherwise.
func (Set) AppendSortedTo ¶ added in v2.4.4
AppendSortedTo appends the sorted subnets of this set to the given slice and returns the resulting slice.
func (Set) Delete ¶ added in v2.4.4
Delete deletes a subnet equal to the given subnet. Returns true if the subnet was deleted, false otherwise.