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 Partition(subnets []*net.IPNet, filter func(int, *net.IPNet) bool) (matched, notMatched []*net.IPNet)
- 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 analyze 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 all of network range b
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