subnet

package
v2.6.1 Latest Latest
Warning

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

Go to latest
Published: May 16, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package subnet contains functions for finding available subnets

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CoveringCIDRs added in v2.3.2

func CoveringCIDRs(ips []net.IP) []*net.IPNet

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

func Covers(a, b *net.IPNet) bool

Covers answers the question if network range a contains all of network range b

func Equal added in v2.3.2

func Equal(a, b *net.IPNet) bool

Equal returns true if a and b have equal IP and masks

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 Unique added in v2.3.2

func Unique(subnets []*net.IPNet) []*net.IPNet

Unique will drop any subnet that is covered by another subnet from the given slice and return the resulting slice. This function will alter the given slice.

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 NewSet added in v2.4.4

func NewSet(subnets []*net.IPNet) Set

func (Set) Add added in v2.4.4

func (s Set) Add(subnet *net.IPNet) bool

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

func (s Set) AppendSortedTo(subnets []*net.IPNet) []*net.IPNet

AppendSortedTo appends the sorted subnets of this set to the given slice and returns the resulting slice

func (Set) Clone added in v2.4.4

func (s Set) Clone() Set

Clone returns a copy of this Set

func (Set) Delete added in v2.4.4

func (s Set) Delete(subnet *net.IPNet) bool

Delete deletes a subnet equal to the given subnet. Returns true if the subnet was deleted, false otherwise

func (Set) Equals added in v2.4.4

func (s Set) Equals(o Set) bool

Equals returns true if the two sets have the same content

func (Set) String added in v2.4.4

func (s Set) String() string

Jump to

Keyboard shortcuts

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