prefix

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2022 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IPv4 = 0
	IPv6 = 1
)

Variables

This section is empty.

Functions

func Allocate

func Allocate(ctx context.Context, parent types.Prefix, name string, length int, store types.Storage) (types.Prefix, error)

Allocate 1. Checks if parent length is superior or equals to length 2. Generates a first candidate with parent-IP/length 3. Gets childs of parent (with store) 4. Checks if there is any collision with childs and candidate (If there is no, go to 6) 5. If there is a collision, get next prefix, set as candidate, and got to 4, if candidate = first candidate, returns an error 6. Save in with the store 7. Gets the childs 8. Checks if only 1 collision (the one we just added)

func AllocateWithBlocklist

func AllocateWithBlocklist(ctx context.Context, parent types.Prefix, name string, length int, store types.Storage, blocklist []string) (types.Prefix, error)

func CollideWith

func CollideWith(prefix string, childs []string) []string

func IsCIDR

func IsCIDR(cidr string) bool

IsCIDR checks if the cidr is not valid

func LastIP

func LastIP(ipNet *net.IPNet) net.IP

LastIP returns the last ip in the network

func New

func New(name string, cidr string, parent types.Prefix) types.Prefix

func NextPrefix

func NextPrefix(ipNet *net.IPNet) *net.IPNet

NextPrefix returns the next prefix e.g.: 169.16.0.0/24 will return 169.16.1.0/24

func OverlappingPrefixes

func OverlappingPrefixes(cidr1 string, cidr2 string) bool

OverlappingPrefixes checks if the 2 parameters are colliding/overlapping e.g.: 192.168.2.1/32 - 192.168.2.0/24 will return true

func PrefixCollideWith

func PrefixCollideWith(prefix types.Prefix, childs []types.Prefix) []types.Prefix

Types

type IPFamily

type IPFamily uint8

func GetFamily

func GetFamily(cidr string) (IPFamily, error)

GetFamily returns the family of the cidr in parameter an error is returned if the cidr is not valid

type Prefix

type Prefix struct {
	Name   string
	Cidr   string
	Parent types.Prefix
}

func (*Prefix) Equals

func (p *Prefix) Equals(prefix types.Prefix) bool

func (*Prefix) GetCidr

func (p *Prefix) GetCidr() string

func (*Prefix) GetName

func (p *Prefix) GetName() string

func (*Prefix) GetParent

func (p *Prefix) GetParent() types.Prefix

Jump to

Keyboard shortcuts

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