ipcritbit

package module
v0.0.0-...-e12181d Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2023 License: MIT Imports: 7 Imported by: 0

README

ATTENTION still in alpha stage!

ipcritbit

A critbit-tree implementation in golang for fast IP lookup.

The original has been forked, modified and reduced to LPM-lookups for net/netip addresses and prefixes. Both IP versions are supported transparently.

Usage

import "github.com/gaissmai/ipcritbit"

type RouteTable struct { // Has unexported fields.  }

func New() RouteTable

func (t RouteTable) Add(p netip.Prefix, value interface{})
func (t RouteTable) Get(p netip.Prefix) (value interface{}, ok bool)
func (t RouteTable) Delete(p netip.Prefix) (value interface{}, ok bool)

func (t RouteTable) LookupIP(ip netip.Addr) (route netip.Prefix, value interface{})
func (t RouteTable) LookupCIDR(p netip.Prefix) (route netip.Prefix, value interface{})

func (t RouteTable) Clear()
func (t RouteTable) Size() int

func (t RouteTable) Walk(callback func(prefix netip.Prefix, value interface{}) bool)
func (t RouteTable) Dump(w io.Writer)

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RouteTable

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

IP routing table.

func New

func New() RouteTable

Create IP routing table

func (RouteTable) Add

func (t RouteTable) Add(p netip.Prefix, value interface{})

Add a route.

func (RouteTable) Clear

func (t RouteTable) Clear()

Deletes all routes.

func (RouteTable) Delete

func (t RouteTable) Delete(p netip.Prefix) (value interface{}, ok bool)

Delete a specific route.

func (RouteTable) Dump

func (t RouteTable) Dump(w io.Writer)

Dump routing table. (for debugging)

func (RouteTable) Get

func (t RouteTable) Get(p netip.Prefix) (value interface{}, ok bool)

Get a specific route.

func (RouteTable) LookupCIDR

func (t RouteTable) LookupCIDR(p netip.Prefix) (route netip.Prefix, value interface{})

Return a specific route by using the longest prefix matching.

func (RouteTable) LookupIP

func (t RouteTable) LookupIP(ip netip.Addr) (route netip.Prefix, value interface{})

Return a specific route by using the longest prefix matching.

func (RouteTable) Size

func (t RouteTable) Size() int

Returns number of routes.

func (RouteTable) Walk

func (t RouteTable) Walk(callback func(prefix netip.Prefix, value interface{}) bool)

Walk iterates all routes. callback is called with route and value as argumets (if callback returns `false`, the iteration is aborted)

Jump to

Keyboard shortcuts

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