flowtrack

package
v1.76.6 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2024 License: BSD-3-Clause Imports: 5 Imported by: 9

Documentation

Overview

Package flowtrack contains types for tracking TCP/UDP flows by 4-tuples.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache[Value any] struct {
	// MaxEntries is the maximum number of cache entries before
	// an item is evicted. Zero means no limit.
	MaxEntries int
	// contains filtered or unexported fields
}

Cache is an LRU cache keyed by Tuple.

The zero value is valid to use.

It is not safe for concurrent access.

func (*Cache[Value]) Add

func (c *Cache[Value]) Add(key Tuple, value Value)

Add adds a value to the cache, set or updating its associated value.

If MaxEntries is non-zero and the length of the cache is greater after any addition, the least recently used value is evicted.

func (*Cache[Value]) Get

func (c *Cache[Value]) Get(key Tuple) (value *Value, ok bool)

Get looks up a key's value from the cache, also reporting whether it was present.

func (*Cache[Value]) Len

func (c *Cache[Value]) Len() int

Len returns the number of items in the cache.

func (*Cache[Value]) Remove

func (c *Cache[Value]) Remove(key Tuple)

Remove removes the provided key from the cache if it was present.

func (*Cache[Value]) RemoveOldest

func (c *Cache[Value]) RemoveOldest()

RemoveOldest removes the oldest item from the cache, if any.

type Tuple

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

Tuple is a 5-tuple of proto, source and destination IP and port.

This struct originally used netip.AddrPort, but that was about twice as slow when used as a map key due to the alignment and extra space for the IPv6 zone pointers (unneeded for all our current 2024-06-17 flowtrack needs).

This struct is packed optimally and doesn't contain gaps or pointers.

func MakeTuple added in v1.70.0

func MakeTuple(proto ipproto.Proto, src, dst netip.AddrPort) Tuple

MakeTuple makes a Tuple out of netip.AddrPort values.

func (Tuple) DstAddr added in v1.70.0

func (t Tuple) DstAddr() netip.Addr

func (Tuple) DstPort added in v1.70.0

func (t Tuple) DstPort() uint16

func (Tuple) MarshalJSON added in v1.70.0

func (t Tuple) MarshalJSON() ([]byte, error)

func (Tuple) SrcAddr added in v1.70.0

func (t Tuple) SrcAddr() netip.Addr

func (Tuple) SrcPort added in v1.70.0

func (t Tuple) SrcPort() uint16

func (Tuple) String

func (t Tuple) String() string

func (*Tuple) UnmarshalJSON added in v1.70.0

func (t *Tuple) UnmarshalJSON(b []byte) error

Jump to

Keyboard shortcuts

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