Documentation
¶
Overview ¶
Package pdump implements the control plane service for packet dumping. This file defines PdumpService, which handles gRPC requests for configuring and managing packet capture modules (identified by name). It keeps the published configuration of every name and serves the capture streams reading it.
Index ¶
- Constants
- type Backend
- type BackendOption
- type Config
- type Module
- type ModuleConfig
- func (m *ModuleConfig) AsFFIModule() ffi.ModuleConfig
- func (m *ModuleConfig) Free() error
- func (m *ModuleConfig) LinkRing(ringName string) error
- func (m *ModuleConfig) SetDumpMode(pbMode uint32) error
- func (m *ModuleConfig) SetFilter(filter string) error
- func (m *ModuleConfig) SetRate(ratePPS uint64) error
- func (m *ModuleConfig) SetSnapLen(snaplen uint32) error
- type Option
- type PdumpModule
- type PdumpService
- func (m *PdumpService) DeleteConfig(ctx context.Context, request *pdumppb.DeleteConfigRequest) (*pdumppb.DeleteConfigResponse, error)
- func (m *PdumpService) ListConfigs(ctx context.Context, request *pdumppb.ListConfigsRequest) (*pdumppb.ListConfigsResponse, error)
- func (m *PdumpService) ReadDump(req *pdumppb.ReadDumpRequest, ...) error
- func (m *PdumpService) SetConfig(ctx context.Context, request *pdumppb.SetConfigRequest) (*pdumppb.SetConfigResponse, error)
- func (m *PdumpService) ShowConfig(ctx context.Context, request *pdumppb.ShowConfigRequest) (*pdumppb.ShowConfigResponse, error)
- func (m *PdumpService) Shutdown()
- type PdumpServiceOption
- type RingHandle
- type RingLease
- type RingOwner
- type Settings
Constants ¶
const MinRingCapacity = uint32(C.PDUMP_MIN_RING_CAPACITY)
MinRingCapacity is the smallest ring capacity a pdump config may capture into, so every record pdump writes fits the ring.
It is PDUMP_MIN_RING_CAPACITY (modules/pdump/dataplane/record.h), read through cgo.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Backend ¶ added in v0.1.0
type Backend interface {
// UpdateModule builds a module config from the settings, links its
// ring by name and publishes it.
//
// On error nothing stays allocated.
UpdateModule(name string, settings Settings) (Module, error)
// DeleteModule removes the module config from the dataplane. It never
// touches the ring the config was linked to.
DeleteModule(name string) error
}
Backend publishes and removes pdump module configs in shared memory.
func NewBackend ¶ added in v0.1.0
func NewBackend(agent *ffi.Agent, options ...BackendOption) Backend
NewBackend creates a backend over the agent's shared memory.
type BackendOption ¶ added in v0.1.0
type BackendOption func(*backendOptions)
BackendOption configures the shared-memory backend.
func WithBackendLog ¶ added in v0.1.0
func WithBackendLog(log *zap.Logger) BackendOption
WithBackendLog sets the logger for the shared-memory backend.
type Config ¶
type Config struct {
ffi.AttachConfig `yaml:",inline"`
Endpoint xcfg.NonEmptyString `yaml:"endpoint"`
DebugEBPF bool `yaml:"debug_ebpf"`
}
func DefaultConfig ¶
func DefaultConfig() *Config
type Module ¶ added in v0.1.0
type Module interface {
// Free releases the module config, reporting ffi.ErrStillReferenced
// while a live generation still holds it.
Free() error
}
Module is a published pdump module config.
It no longer exposes rings: a stream reads its capture's binding, which outlives any one module generation across a same-object update.
type ModuleConfig ¶
type ModuleConfig struct {
// contains filtered or unexported fields
}
func NewModuleConfig ¶
func NewModuleConfig(agent *ffi.Agent, name string) (*ModuleConfig, error)
func (*ModuleConfig) AsFFIModule ¶
func (m *ModuleConfig) AsFFIModule() ffi.ModuleConfig
func (*ModuleConfig) Free ¶
func (m *ModuleConfig) Free() error
Free destroys the module config, or reports ffi.ErrStillReferenced while a live generation still holds it. Safe to call multiple times.
func (*ModuleConfig) LinkRing ¶ added in v0.2.0
func (m *ModuleConfig) LinkRing(ringName string) error
LinkRing records the ring this config captures into, by name.
The dataplane resolves the link to a ring object when it next rebuilds its execution contexts; whether a ring by this name exists is not checked here. The caller establishes that order itself: the ring-service lease is taken, and the name is known to resolve, before this link is published.
func (*ModuleConfig) SetDumpMode ¶
func (m *ModuleConfig) SetDumpMode(pbMode uint32) error
func (*ModuleConfig) SetFilter ¶
func (m *ModuleConfig) SetFilter(filter string) error
func (*ModuleConfig) SetRate ¶ added in v0.2.0
func (m *ModuleConfig) SetRate(ratePPS uint64) error
func (*ModuleConfig) SetSnapLen ¶
func (m *ModuleConfig) SetSnapLen(snaplen uint32) error
type PdumpModule ¶
type PdumpModule struct {
// contains filtered or unexported fields
}
PdumpModule is a control-plane component of a packet dump module.
It also hosts the ring service. That service owns the standalone named rings created through this agent.
func NewPdumpModule ¶
func NewPdumpModule(cfg *Config, options ...Option) (*PdumpModule, error)
func (*PdumpModule) Endpoint ¶
func (m *PdumpModule) Endpoint() string
func (*PdumpModule) Name ¶
func (m *PdumpModule) Name() string
func (*PdumpModule) RegisterService ¶
func (m *PdumpModule) RegisterService(server *grpc.Server)
func (*PdumpModule) Run ¶
func (m *PdumpModule) Run(ctx context.Context) error
Run runs the module until the specified context is canceled. Implements the gateway.BackgroundService interface.
func (*PdumpModule) ServicesNames ¶
func (m *PdumpModule) ServicesNames() []string
type PdumpService ¶
type PdumpService struct {
pdumppb.UnimplementedPdumpServiceServer
// contains filtered or unexported fields
}
PdumpService provides packet capture functionality through a gRPC interface. It manages packet capture configurations and the bindings their streams read.
func NewPdumpService ¶
func NewPdumpService(backend Backend, ringOwner RingOwner, options ...PdumpServiceOption) *PdumpService
NewPdumpService initializes a new packet capture service.
The ring owner resolves the ring names configs bind to; production passes the ring service this agent hosts, a test fakes it.
func (*PdumpService) DeleteConfig ¶
func (m *PdumpService) DeleteConfig( ctx context.Context, request *pdumppb.DeleteConfigRequest, ) (*pdumppb.DeleteConfigResponse, error)
DeleteConfig removes a packet capture configuration.
The ring the config was linked to is never deleted.
func (*PdumpService) ListConfigs ¶
func (m *PdumpService) ListConfigs( ctx context.Context, request *pdumppb.ListConfigsRequest, ) (*pdumppb.ListConfigsResponse, error)
ListConfigs retrieves all configured packet capture modules.
func (*PdumpService) ReadDump ¶
func (m *PdumpService) ReadDump(req *pdumppb.ReadDumpRequest, stream grpc.ServerStreamingServer[pdumppb.Record]) error
ReadDump streams captured packets from the specified packet capture module.
The stream continues until one of the following termination conditions occurs:
- The client disconnects (context cancellation from the gRPC stream)
- The service is shut down
- An error occurs while sending a packet record on the stream
- The configuration of this module is deleted or rebound to another ring
Every request reads its binding's ring through its own read positions, so concurrent ReadDump requests do not interfere with each other. The handler returns only after its readers have stopped reading those rings.
func (*PdumpService) SetConfig ¶
func (m *PdumpService) SetConfig( ctx context.Context, request *pdumppb.SetConfigRequest, ) (*pdumppb.SetConfigResponse, error)
SetConfig updates or creates packet capture configuration.
Only the config fields the request carries change. ring_name is required to create a config, keeps the bound ring when absent on an update, and is invalid when carried empty. A newly bound ring must exist and be at least the pdump minimum capacity, whatever the snaplen; a same-object update keeps its binding without a new check. On any failure the published config, its binding and its streams are left exactly as they were.
func (*PdumpService) ShowConfig ¶
func (m *PdumpService) ShowConfig( ctx context.Context, request *pdumppb.ShowConfigRequest, ) (*pdumppb.ShowConfigResponse, error)
ShowConfig retrieves the current configuration for a specific packet capture module.
func (*PdumpService) Shutdown ¶
func (m *PdumpService) Shutdown()
Shutdown ends every active ReadDump stream.
Each handler returns only after the readers it started have stopped, so the shared memory may be released once the handlers have drained.
type PdumpServiceOption ¶
type PdumpServiceOption func(*pdumpServiceOptions)
PdumpServiceOption configures a packet capture service.
func WithPdumpServiceLog ¶
func WithPdumpServiceLog(log *zap.Logger) PdumpServiceOption
WithPdumpServiceLog sets the logger for a packet capture service.
type RingHandle ¶ added in v0.2.0
RingHandle identifies one ring from its create to its delete.
type RingLease ¶ added in v0.2.0
type RingLease interface {
// Handle returns the handle this lease pins.
//
// A binding compares handles, not names, to tell a same-object update
// from a rebind: a ring deleted and recreated under the same name
// gets a new handle.
Handle() RingHandle
// Release removes this lease's block on the ring's delete.
//
// It is safe to call more than once.
Release()
// Capacity returns the size of each worker's data area in bytes.
//
// It is the bound a reader checks a record's length against to tell
// a real frame from corruption.
Capacity() uint32
// Sources returns a record source per worker's ring, indexed by
// worker, for a reader to read from.
Sources() ([]cring.RecordSource, error)
}
RingLease is what a capture binding needs from an acquired ring.
It must be enough to tell whether two leases pin the same ring, to check a ring meets the pdump minimum capacity on bind and to bound a reader's records against that same capacity, to read the ring's sources and to let the ring go again. A production lease pins a ring hosted in this agent; a test fakes one directly, with no dataplane ring object underneath.
type RingOwner ¶ added in v0.2.0
type RingOwner interface {
// LookupHandle returns the handle registered under a name.
LookupHandle(name string) (RingHandle, bool)
// Acquire blocks the delete of the named ring and returns a lease.
//
// It succeeds only if the name still maps to the given handle.
Acquire(name string, handle RingHandle) (RingLease, error)
}
RingOwner is where the pdump service looks up and pins its rings.
Production resolves rings in the ring service hosted in this agent. A test fakes it with in-memory record sources, since pdump's C library stubs DPDK and cannot link the real ring object's CGo harness.