network

package
v1.8.5 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrorCorrupted = fmt.Errorf("packet corrupted")
View Source
var ErrorTooShort = fmt.Errorf("packet too short")

Functions

func CIDRsToPrefix added in v1.8.2

func CIDRsToPrefix(cidrs string) []netip.Prefix

CIDRsToPrefix given a comma separated list with CIDRS it returns a slice of netip.Prefixes and remove duplicates

func EncodeWithAlignment added in v1.8.1

func EncodeWithAlignment(data any) []byte

func FirstAndNextSubnetAddr added in v1.8.1

func FirstAndNextSubnetAddr(subnet netip.Prefix) (first, next netip.Addr, err error)

FirstAndNextSubnetAddr takes the beginning address of an entire network in CIDR notation (e.g. 192.168.1.0/24) and returns the first addresses within the network and the first address of the next network (e.g. first 192.168.1.0, next 192.168.2.0).

Note: nftables needs half-open intervals [firstIP, lastIP) for prefixes e.g. 10.0.0.0/24 becomes [10.0.0.0, 10.0.1.0), 10.1.1.1/32 becomes [10.1.1.1, 10.1.1.2) etc

func SetChecksumOffloading

func SetChecksumOffloading(ifName string, rxOn, txOn bool) error

SetChecksumOffloading enables/disables Rx/Tx checksum offloading for the given interface.

func SplitCIDRs

func SplitCIDRs(cidrs string) ([]string, []string)

SplitCIDRs given a comma separated list with CIDRS it returns 2 slice of strings per IP family

func SplitCIDRslice

func SplitCIDRslice(cidrs []string) ([]string, []string)

func TopLevelPrefixes added in v1.8.2

func TopLevelPrefixes(prefixes []netip.Prefix) ([]netip.Prefix, []netip.Prefix)

TopLevelPrefixes given a list of prefixes return only the top level prefixes It returns an IPv4 and IPv6 list.

Types

type Packet added in v1.8.1

type Packet struct {
	ID      uint32
	Family  v1.IPFamily
	SrcIP   net.IP
	DstIP   net.IP
	Proto   v1.Protocol
	SrcPort int
	DstPort int
	Payload []byte
}

func (Packet) MarshalLog added in v1.8.1

func (p Packet) MarshalLog() any

This function is used for JSON output (interface logr.Marshaler)

func (Packet) String added in v1.8.1

func (p Packet) String() string

type Tree added in v1.8.2

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

Tree is a radix tree for IPv4 and IPv6 networks.

func NewIPTree added in v1.8.2

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

NewIPTree creates a new Radix Tree for IP addresses.

func (*Tree[T]) DeletePrefix added in v1.8.2

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

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

func (*Tree[T]) DepthFirstWalk added in v1.8.2

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 added in v1.8.2

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 added in v1.8.2

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 added in v1.8.2

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 added in v1.8.2

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

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

func (*Tree[T]) LongestPrefixMatch added in v1.8.2

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 added in v1.8.2

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 added in v1.8.2

func (t *Tree[T]) TopLevelPrefixes(isIPv6 bool) map[netip.Prefix]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 added in v1.8.2

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 added in v1.8.2

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

WalkPrefix is used to walk the tree under a prefix

type WalkFn added in v1.8.2

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