cidrs

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2024 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IPMapper

type IPMapper[V comparable] interface {
	GetIP(ip netip.Addr) (value V, matches bool)
}

IPMapper represents an type can perform a get on a map of netip.Addr to value V, typically implemented against netip.Prefix data

See TrieMap for an efficient implementation

func NewBruteForceMapper

func NewBruteForceMapper[V comparable](mapping map[V][]netip.Prefix) IPMapper[V]

NewBruteForceMapper returns a naive IPMapper that loops over the map and compares all netip.Prefix

This type exists purely for testing and benchmarking

type TrieMap

type TrieMap[V comparable] struct {
	// contains filtered or unexported fields
}

TrieMap contains an efficient trie structure of netip.Prefix that can match a netip.Addr to the associated Prefix if any and return the value associated with it of type V.

Use NewTrieMap to instantiate

NOTE: This is insert-only (no delete) and insertion is *not* thread-safe.

Currently this is a simple TrieMap, in the future it may have compression.

See: https://vincent.bernat.ch/en/blog/2017-ipv4-route-lookup-linux

For benchmarks with real data see ./aws/mapper_test.go

func NewTrieMap

func NewTrieMap[V comparable]() *TrieMap[V]

NewTrieMap[V] returns a new, properly allocated TrieMap[V]

func (*TrieMap[V]) GetIP

func (t *TrieMap[V]) GetIP(ip netip.Addr) (value V, contains bool)

GetIP returns the associated value for the matching cidr if any with contains=true, or else the default value of V and contains=false

func (*TrieMap[V]) Insert

func (t *TrieMap[V]) Insert(cidr netip.Prefix, value V)

Insert inserts value into TrieMap by index cidr You can later match a netip.Addr to value with GetIP

Jump to

Keyboard shortcuts

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