iptree

package
v1.30.0-beta.0 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Tree

type Tree[T any] struct {
	// contains filtered or unexported fields
}

Tree is a radix tree for IPv4 and IPv6 networks.

func New

func New[T any]() *Tree[T]

New creates a new Radix Tree for IP addresses.

func (*Tree[T]) DeletePrefix

func (t *Tree[T]) DeletePrefix(prefix netip.Prefix) bool

DeletePrefix delete the exact prefix and return true if it existed.

func (*Tree[T]) DepthFirstWalk

func (t *Tree[T]) DepthFirstWalk(isIPv6 bool, fn WalkFn[T])

DepthFirstWalk is used to walk the tree of the corresponding IP family

func (*Tree[T]) GetHostIPPrefixMatches

func (t *Tree[T]) GetHostIPPrefixMatches(ip netip.Addr) map[netip.Prefix]T

GetHostIPPrefixMatches returns the list of prefixes that contain the specified Host IP. An IP is considered a Host IP if is within the subnet range and is not the network address or, if IPv4, the broadcast address (RFC 1878).

func (*Tree[T]) GetPrefix

func (t *Tree[T]) GetPrefix(prefix netip.Prefix) (T, bool)

GetPrefix returns the stored value and true if the exact prefix exists in the tree.

func (*Tree[T]) InsertPrefix

func (t *Tree[T]) InsertPrefix(prefix netip.Prefix, v T) bool

InsertPrefix is used to add a new entry or update an existing entry. Returns true if updated.

func (*Tree[T]) Len

func (t *Tree[T]) Len(isV6 bool) int

for testing, returns the number of public nodes in the tree.

func (*Tree[T]) LongestPrefixMatch

func (t *Tree[T]) LongestPrefixMatch(prefix netip.Prefix) (netip.Prefix, T, bool)

LongestPrefixMatch returns the longest prefix match, the stored value and true if exist. For example, considering the following prefixes 192.168.20.16/28 and 192.168.0.0/16, when the address 192.168.20.19/32 is looked up it will return 192.168.20.16/28.

func (*Tree[T]) ShortestPrefixMatch

func (t *Tree[T]) ShortestPrefixMatch(prefix netip.Prefix) (netip.Prefix, T, bool)

ShortestPrefixMatch returns the shortest prefix match, the stored value and true if exist. For example, considering the following prefixes 192.168.20.16/28 and 192.168.0.0/16, when the address 192.168.20.19/32 is looked up it will return 192.168.0.0/16.

func (*Tree[T]) TopLevelPrefixes

func (t *Tree[T]) TopLevelPrefixes(isIPv6 bool) map[string]T

TopLevelPrefixes is used to return a map with all the Top Level prefixes from the corresponding IP family and its values. For example, if the tree contains entries for 10.0.0.0/8, 10.1.0.0/16, and 192.168.0.0/16, this will return 10.0.0.0/8 and 192.168.0.0/16.

func (*Tree[T]) WalkPath

func (t *Tree[T]) WalkPath(path netip.Prefix, fn WalkFn[T])

WalkPath is used to walk the tree, but only visiting nodes from the root down to a given IP prefix. Where WalkPrefix walks all the entries *under* the given prefix, this walks the entries *above* the given prefix.

func (*Tree[T]) WalkPrefix

func (t *Tree[T]) WalkPrefix(prefix netip.Prefix, fn WalkFn[T])

WalkPrefix is used to walk the tree under a prefix

type WalkFn

type WalkFn[T any] func(s netip.Prefix, v T) bool

WalkFn is used when walking the tree. Takes a key and value, returning if iteration should be terminated.

Jump to

Keyboard shortcuts

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