networking

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrIncompatibleIPFamily = errors.New("incompatible IP family")
	ErrInvalidFamily        = errors.New("invalid family")
	ErrInvalidIP            = errors.New("invalid IP")
	ErrIncompatiblePrefix   = errors.New("incompatible prefix")
)

Functions

func DefaultInterface

func DefaultInterface() (string, error)

func First

func First(ipnet *net.IPNet) net.IP

func Last

func Last(ipnet *net.IPNet) net.IP

func NextBy

func NextBy(ip netip.Addr, by int) netip.Addr

func Overlap

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

func ParseIP

func ParseIP(ip string) (net.IP, error)

func PrevBy

func PrevBy(ip netip.Addr, by int) netip.Addr

Types

type BasicSubnetAllocator

type BasicSubnetAllocator struct {
	// contains filtered or unexported fields
}

func NewBasicSubnetAllocator

func NewBasicSubnetAllocator(pool SubnetPool) (*BasicSubnetAllocator, error)

func (*BasicSubnetAllocator) Allocate

func (a *BasicSubnetAllocator) Allocate(network *Network) error

func (*BasicSubnetAllocator) AllocateNext

func (a *BasicSubnetAllocator) AllocateNext() (Network, error)

func (*BasicSubnetAllocator) Release

func (a *BasicSubnetAllocator) Release(subnet *Network) error

type IPFamily

type IPFamily string
const (
	IPv4 IPFamily = "ipv4"
	IPv6 IPFamily = "ipv6"
)

func (IPFamily) Size

func (f IPFamily) Size() int

func (IPFamily) String

func (f IPFamily) String() string

type Network

type Network struct {
	Family       IPFamily `json:"family"`
	IP           net.IP   `json:"ip"`
	PrefixLength int      `json:"prefix_length"`
}

func (*Network) Contains

func (n *Network) Contains(ip net.IP) bool

func (*Network) ContainsNetwork

func (n *Network) ContainsNetwork(other *Network) bool

func (*Network) FirstAddress

func (n *Network) FirstAddress() netip.Addr

func (*Network) IPNet

func (n *Network) IPNet() *net.IPNet

func (*Network) LastAddress

func (n *Network) LastAddress() netip.Addr

func (*Network) MarshalJSON

func (n *Network) MarshalJSON() ([]byte, error)

func (*Network) UnmarshalJSON

func (n *Network) UnmarshalJSON(data []byte) error

func (*Network) Validate

func (n *Network) Validate() error

type SubnetAllocator

type SubnetAllocator interface {
	Allocate(*Network) error
	Release(*Network) error
	AllocateNext() (Network, error)
}

type SubnetPool

type SubnetPool struct {
	Network      Network
	SubnetPrefix int
}

func (SubnetPool) AddressesBySubnet

func (p SubnetPool) AddressesBySubnet() int

Jump to

Keyboard shortcuts

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