Documentation
¶
Overview ¶
Package capture is used to set up packet capturing and specifies the flow format. The API to interact with the capture manager is specified in a sub-package.
Index ¶
- Constants
- Variables
- func ParsePacketV4(ipLayer capture.IPLayer) (epHash capturetypes.EPHashV4, auxInfo byte, errno capturetypes.ParsingErrno)
- func ParsePacketV6(ipLayer capture.IPLayer) (epHash capturetypes.EPHashV6, auxInfo byte, errno capturetypes.ParsingErrno)
- type Capture
- type Flow
- type FlowInfo
- type FlowInfos
- type FlowLog
- type LocalBuffer
- func (l *LocalBuffer) Add(epHash []byte, pktType byte, pktSize uint32, isIPv4 bool, auxInfo byte, ...) (ok bool)
- func (l *LocalBuffer) Assign(data []byte)
- func (l *LocalBuffer) Next() ([]byte, byte, uint32, bool, byte, capturetypes.ParsingErrno, bool)
- func (l *LocalBuffer) Reset()
- func (l *LocalBuffer) Usage() float64
- type LocalBufferPool
- type Manager
- func (cm *Manager) Close(ctx context.Context, ifaces ...string)
- func (cm *Manager) Config(ifaces ...string) (ifaceConfigs config.Ifaces)
- func (cm *Manager) GetFlowMaps(ctx context.Context, filterFn goDB.FilterFn, ...)
- func (cm *Manager) GetTimestamps() (startedAt, lastRotation time.Time)
- func (cm *Manager) LastRotation() (t time.Time)
- func (cm *Manager) ScheduleWriteouts(ctx context.Context, interval time.Duration)
- func (cm *Manager) StartedAt() (t time.Time)
- func (cm *Manager) Status(ctx context.Context, ifaces ...string) (statusmap capturetypes.InterfaceStats)
- func (cm *Manager) Update(ctx context.Context, ifaces config.Ifaces) (enabled, updated, disabled capturetypes.IfaceChanges, err error)
- type ManagerOption
- type Metrics
- func (m *Metrics) ObserveBytesTotal(iface, direction string) prometheus.Counter
- func (m *Metrics) ObserveCaptureIssues(iface, issueType string) prometheus.Counter
- func (m *Metrics) ObserveGlobalBufferUsage(iface string) prometheus.Gauge
- func (m *Metrics) ObserveNumFlows(iface string) prometheus.Gauge
- func (m *Metrics) ObserveNumIfacesCapturing() prometheus.Gauge
- func (m *Metrics) ObservePacketsDropped(iface string) prometheus.Counter
- func (m *Metrics) ObservePacketsProcessed(iface string) prometheus.Counter
- func (m *Metrics) ObservePacketsTotal(iface, direction string) prometheus.Counter
- func (m *Metrics) ObserveRotationDuration() prometheus.Histogram
- func (m *Metrics) ResetCountersTestingOnly()
- type MetricsOption
- type RunGroup
- type Source
Constants ¶
const (
// MaxIfaces is the maximum number of interfaces we can monitor
MaxIfaces = 1024
)
Variables ¶
var ( // DefaultRotationDurationHistogramBins provides a reasonable standard set of histogram bins DefaultRotationDurationHistogramBins = []float64{0.001, 0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 0.75, 1} )
var ( // ErrLocalBufferOverflow signifies that the local packet buffer is full ErrLocalBufferOverflow = errors.New("local packet buffer overflow") )
Functions ¶
func ParsePacketV4 ¶
func ParsePacketV4(ipLayer capture.IPLayer) (epHash capturetypes.EPHashV4, auxInfo byte, errno capturetypes.ParsingErrno)
ParsePacketV4 processes / extracts all information contained in the v6 IP layer received from a capture source and converts it to a hash and flags to be added to the flow map
func ParsePacketV6 ¶
func ParsePacketV6(ipLayer capture.IPLayer) (epHash capturetypes.EPHashV6, auxInfo byte, errno capturetypes.ParsingErrno)
ParsePacketV6 processes / extracts all information contained in the v6 IP layer received from a capture source and converts it to a hash and flags to be added to the flow map
Types ¶
type Capture ¶
type Capture struct { // Mutex to allow concurrent access to capture components // This is _unrelated_ to the three-point capture lock to // interrupt the capture for purposes of e.g. rotation sync.Mutex // contains filtered or unexported fields }
Capture captures and logs flow data for all traffic on a given network interface. For each Capture, a goroutine is spawned at creation time. To avoid leaking this goroutine, be sure to call Close() when you're done with a Capture.
Each capture is associated with a network interface when created. This interface can never be changed.
All public methods of Capture are threadsafe.
func (*Capture) SetSourceInitFn ¶
SetSourceInitFn sets a custom function used to initialize a new capture
type Flow ¶
Flow stores a goProbe flow (alias for types.Counters to allow for extension with flow specific methods)
func NewFlow ¶
func NewFlow(pktType capture.PacketType, pktTotalLen uint32) *Flow
NewFlow creates a new flow based on the packet
func (*Flow) UpdateFlow ¶
func (f *Flow) UpdateFlow(pktType capture.PacketType, pktTotalLen uint32)
UpdateFlow increments flow counters if the packet belongs to an existing flow
type FlowInfo ¶
type FlowInfo struct { Idle bool `json:"idle"` DirectionConfidenceHigh bool `json:"direction_confidence_high"` Flow results.ExtendedRow `json:"flow"` }
FlowInfo summarizes information about a given flow
type FlowLog ¶
type FlowLog struct {
// contains filtered or unexported fields
}
FlowLog stores flows. It is NOT threadsafe.
func (*FlowLog) Aggregate ¶
func (f *FlowLog) Aggregate() (agg *hashmap.AggFlowMap)
Aggregate extracts an AggFlowMap from the currently active flowMap. The flowMap itself is not modified in the process.
Returns an AggFlowMap containing all flows since the last call to Rotate.
func (*FlowLog) MarshalJSON ¶
MarshalJSON implements the jsoniter.Marshaler interface
func (*FlowLog) Rotate ¶
func (f *FlowLog) Rotate() (agg *hashmap.AggFlowMap, totals *types.Counters)
Rotate rotates the flow log. All flows are reset to no packets and traffic. Moreover, any flows not worth keeping (according to Flow.IsWorthKeeping) are discarded.
Returns an AggFlowMap containing all flows since the last call to Rotate.
type LocalBuffer ¶
type LocalBuffer struct {
// contains filtered or unexported fields
}
LocalBuffer denotes a local packet buffer used to temporarily capture packets from the source (e.g. during rotation) to avoid a ring / kernel buffer overflow
func NewLocalBuffer ¶
func NewLocalBuffer(memPool *LocalBufferPool) *LocalBuffer
NewLocalBuffer initializes a new local buffer using a global memory pool and a maximum buffer size
func (*LocalBuffer) Add ¶
func (l *LocalBuffer) Add(epHash []byte, pktType byte, pktSize uint32, isIPv4 bool, auxInfo byte, errno capturetypes.ParsingErrno) (ok bool)
Add adds an element to the buffer, returning ok = true if successful If the buffer is full / may not grow any further, ok is false
func (*LocalBuffer) Assign ¶
func (l *LocalBuffer) Assign(data []byte)
Assign sets the actual underlying data slice (obtained from a memory pool) of this buffer
func (*LocalBuffer) Next ¶
func (l *LocalBuffer) Next() ([]byte, byte, uint32, bool, byte, capturetypes.ParsingErrno, bool)
Next fetches the i-th element from the buffer
func (*LocalBuffer) Usage ¶
func (l *LocalBuffer) Usage() float64
Usage return the relative fraction of the buffer capacity in use (i.e. written to, independent of number of items already retreived by Next())
type LocalBufferPool ¶
type LocalBufferPool struct { NBuffers int MaxBufferSize int *concurrency.MemPoolLimitUnique }
LocalBufferPool provides a wrapper around a MemPoolLimitUnique with a maximum size
func NewLocalBufferPool ¶
func NewLocalBufferPool(nBuffers, maxBufferSize int) *LocalBufferPool
NewLocalBufferPool initializes a new local buffer pool
type Manager ¶
Manager manages a set of Capture instances. Each interface can be associated with up to one Capture.
func InitManager ¶
func InitManager(ctx context.Context, config *config.Config, opts ...ManagerOption) (*Manager, error)
InitManager initializes a CaptureManager and the underlying writeout logic Used as primary entrypoint for the goProbe binary and E2E tests
func NewManager ¶
func NewManager(writeoutHandler writeout.Handler, opts ...ManagerOption) *Manager
NewManager creates a new CaptureManager
func (*Manager) Config ¶
Config returns the runtime config of the capture manager for all (or a set of) interfaces
func (*Manager) GetFlowMaps ¶
func (cm *Manager) GetFlowMaps(ctx context.Context, filterFn goDB.FilterFn, writeoutChan chan<- hashmap.AggFlowMapWithMetadata, ifaces ...string)
GetFlowMaps extracts a copy of all active flows and sends them on the provided channel (compatible with normal query processing). This way, live data can be added to a query result
func (*Manager) GetTimestamps ¶
GetTimestamps is a combination of LastRotation() and StartedAt(). It exists to save a lock in case both timestamps are requested
func (*Manager) LastRotation ¶
LastRotation returns the timestamp of the last DB writeout / rotation
func (*Manager) ScheduleWriteouts ¶
ScheduleWriteouts creates a new goroutine that executes a DB writeout in defined time intervals
func (*Manager) StartedAt ¶
StartedAt returns the timestamp when the capture manager was initialized
func (*Manager) Status ¶
func (cm *Manager) Status(ctx context.Context, ifaces ...string) (statusmap capturetypes.InterfaceStats)
Status fetches the current capture stats from all (or a set of) interfaces
func (*Manager) Update ¶
func (cm *Manager) Update(ctx context.Context, ifaces config.Ifaces) (enabled, updated, disabled capturetypes.IfaceChanges, err error)
Update the configuration for all (or a set of) interfaces
type ManagerOption ¶
type ManagerOption func(cm *Manager)
ManagerOption denotes a functional option for any CaptureManager
func WithLocalBuffers ¶
func WithLocalBuffers(nBuffers, sizeLimit int) ManagerOption
WithLocalBuffers sets one or multiple local buffers for the capture manager
func WithMetrics ¶
func WithMetrics(metrics *Metrics) ManagerOption
WithMetrics enables / sets tracking of metrics
func WithSkipWriteoutSchedule ¶
func WithSkipWriteoutSchedule(skip bool) ManagerOption
WithSkipWriteoutSchedule disables scheduled writeouts
func WithSourceInitFn ¶
func WithSourceInitFn(fn sourceInitFn) ManagerOption
WithSourceInitFn sets a custom function used to initialize a new capture
type Metrics ¶
type Metrics struct {
// contains filtered or unexported fields
}
Metrics denotes all capture-specific metrics, tracked in Prometheus
func NewMetrics ¶
func NewMetrics(opts ...MetricsOption) *Metrics
NewMetrics instantiates a new set of capture metrics
func (*Metrics) ObserveBytesTotal ¶
func (m *Metrics) ObserveBytesTotal(iface, direction string) prometheus.Counter
ObserveBytesTotal returns the counter metric relevant for the provided labels
func (*Metrics) ObserveCaptureIssues ¶
func (m *Metrics) ObserveCaptureIssues(iface, issueType string) prometheus.Counter
ObserveCaptureIssues returns the counter metric relevant for the provided labels
func (*Metrics) ObserveGlobalBufferUsage ¶
func (m *Metrics) ObserveGlobalBufferUsage(iface string) prometheus.Gauge
ObserveGlobalBufferUsage returns the gauge metric relevant for the provided labels
func (*Metrics) ObserveNumFlows ¶
func (m *Metrics) ObserveNumFlows(iface string) prometheus.Gauge
ObserveNumFlows returns the gauge metric relevant for the provided labels
func (*Metrics) ObserveNumIfacesCapturing ¶
func (m *Metrics) ObserveNumIfacesCapturing() prometheus.Gauge
ObserveNumIfacesCapturing returns the gauge metric
func (*Metrics) ObservePacketsDropped ¶
func (m *Metrics) ObservePacketsDropped(iface string) prometheus.Counter
ObservePacketsDropped returns the counter metric relevant for the provided labels
func (*Metrics) ObservePacketsProcessed ¶
func (m *Metrics) ObservePacketsProcessed(iface string) prometheus.Counter
ObservePacketsProcessed returns the counter metric relevant for the provided labels
func (*Metrics) ObservePacketsTotal ¶
func (m *Metrics) ObservePacketsTotal(iface, direction string) prometheus.Counter
ObservePacketsTotal returns the counter metric relevant for the provided labels
func (*Metrics) ObserveRotationDuration ¶
func (m *Metrics) ObserveRotationDuration() prometheus.Histogram
ObserveRotationDuration returns the histogram metric
func (*Metrics) ResetCountersTestingOnly ¶
func (m *Metrics) ResetCountersTestingOnly()
ResetCountersTestingOnly allows to externally reset all Prometheus counters (e.g. for testing purposes or in order to manually reset all of them) This method must not (and cannot) be called outside of testing
type MetricsOption ¶
type MetricsOption func(*Metrics)
MetricsOption denotes a functional option for Metrics
func DisableIfaceTracking ¶
func DisableIfaceTracking() MetricsOption
DisableIfaceTracking removes the "iface" label from all Prometheus metrics (reducing cardinality, in particular if many interfaces from many sensors are being tracked)
type RunGroup ¶
type RunGroup struct {
// contains filtered or unexported fields
}
RunGroup wraps the common waitgroup setup for go routines that need to finish before continuing with instruction execution.
type Source ¶
type Source = capture.SourceZeroCopy
Source redefines any slimcap zero copy source interface type