iputil

package
v1.32.3 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AggregatePrefixes

func AggregatePrefixes(prefixes []netip.Prefix) []netip.Prefix

AggregatePrefixes merges overlapping or adjacent prefixes into a single prefix. It combines prefixes that can be represented by a larger, more inclusive prefix.

Examples:

func AggregatePrefixesWithPrefixTree

func AggregatePrefixesWithPrefixTree(prefixes []netip.Prefix) []netip.Prefix

AggregatePrefixesWithPrefixTree merges overlapping or adjacent prefixes into a single prefix.

This function uses a prefix tree to aggregate the input prefixes. While it achieves the same result as AggregatePrefixes, it is less efficient. For better performance, use AggregatePrefixes instead.

Examples:

func AreAddressesFromSameFamily

func AreAddressesFromSameFamily(addresses []netip.Addr) bool

func ArePrefixesFromSameFamily

func ArePrefixesFromSameFamily(prefixes []netip.Prefix) bool

func ContainsPrefix

func ContainsPrefix(p netip.Prefix, o netip.Prefix) bool

ContainsPrefix checks if prefix p fully contains prefix o. It returns true if o is a subset of p, meaning all addresses in o are also in p. This is true when p overlaps with o and p has fewer or equal number of bits than o.

func GroupAddressesByFamily

func GroupAddressesByFamily(vs []netip.Addr) ([]netip.Addr, []netip.Addr)

func GroupPrefixesByFamily

func GroupPrefixesByFamily(vs []netip.Prefix) ([]netip.Prefix, []netip.Prefix)

GroupPrefixesByFamily groups prefixes by IP family.

func IsPrefixesAllowAll

func IsPrefixesAllowAll(prefixes []netip.Prefix) bool

IsPrefixesAllowAll returns true if one of the prefixes allows all addresses. FIXME: it should return true if the aggregated prefix allows all addresses. Now it only checks one by one.

func ParseAddresses

func ParseAddresses(vs []string) ([]netip.Addr, error)

func ParsePrefix

func ParsePrefix(v string) (netip.Prefix, error)

ParsePrefix parses a CIDR string and returns a Prefix.

Types

type Family

type Family string
const (
	IPv4 Family = "IPv4"
	IPv6 Family = "IPv6"
)

func FamilyOfAddr

func FamilyOfAddr(addr netip.Addr) Family

Jump to

Keyboard shortcuts

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