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 interacts with data plane agents via FFI (Foreign Function Interface) to apply capture settings (filters, mode, snaplen, ring buffer size) and to facilitate reading captured packets from shared ring buffers.
Index ¶
- type Config
- type ModuleConfig
- func (m *ModuleConfig) AsFFIModule() ffi.ModuleConfig
- func (m *ModuleConfig) Free() error
- func (m *ModuleConfig) SetDumpMode(pbMode uint32) error
- func (m *ModuleConfig) SetFilter(filter string) error
- func (m *ModuleConfig) SetSnapLen(snaplen uint32) error
- func (m *ModuleConfig) SetupRing(ring *ringBuffer) error
- type ModuleConfigOption
- 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) ReclaimDeferred()
- 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
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// InstanceID specifies which dataplane instance this module serves.
//
// Required: a listed module must set it explicitly, even to 0.
InstanceID xcfg.Required[uint32] `yaml:"instance_id"`
// MemoryPath is the path to the shared-memory file that is used to
// communicate with dataplane.
MemoryPath xcfg.NonEmptyString `yaml:"memory_path"`
// MemoryRequirements is the amount of memory that is required for a single
// transaction.
MemoryRequirements xcfg.NonZero[datasize.ByteSize] `yaml:"memory_requirements"`
Endpoint xcfg.NonEmptyString `yaml:"endpoint"`
DebugEBPF bool `yaml:"debug_ebpf"`
}
func DefaultConfig ¶
func DefaultConfig() *Config
type ModuleConfig ¶
type ModuleConfig struct {
// contains filtered or unexported fields
}
func NewModuleConfig ¶
func NewModuleConfig( agent *ffi.Agent, name string, options ...ModuleConfigOption, ) (*ModuleConfig, error)
func (*ModuleConfig) AsFFIModule ¶
func (m *ModuleConfig) AsFFIModule() ffi.ModuleConfig
func (*ModuleConfig) Free ¶
func (m *ModuleConfig) Free() error
Free destroys the module config when it is dangling — referenced by no live configuration generation — and reports nil. While a live generation still references it the free is refused with ffi.ErrStillReferenced and the handle stays usable: the caller must remember it and free it again once the generations holding it drain. Safe to call multiple times: subsequent calls are no-ops reporting nil.
func (*ModuleConfig) SetDumpMode ¶
func (m *ModuleConfig) SetDumpMode(pbMode uint32) error
func (*ModuleConfig) SetFilter ¶
func (m *ModuleConfig) SetFilter(filter string) error
func (*ModuleConfig) SetSnapLen ¶
func (m *ModuleConfig) SetSnapLen(snaplen uint32) error
func (*ModuleConfig) SetupRing ¶
func (m *ModuleConfig) SetupRing(ring *ringBuffer) error
type ModuleConfigOption ¶
type ModuleConfigOption func(*moduleConfigOptions)
ModuleConfigOption configures a pdump module configuration.
func WithModuleConfigLog ¶
func WithModuleConfigLog(log *zap.Logger) ModuleConfigOption
WithModuleConfigLog sets the logger for a pdump module configuration.
type PdumpModule ¶
type PdumpModule struct {
// contains filtered or unexported fields
}
PdumpModule is a control-plane component of a packet dump module.
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 ring buffers.
func NewPdumpService ¶
func NewPdumpService(agent *ffi.Agent, options ...PdumpServiceOption) *PdumpService
NewPdumpService initializes a new packet capture service.
func (*PdumpService) DeleteConfig ¶
func (m *PdumpService) DeleteConfig( ctx context.Context, request *pdumppb.DeleteConfigRequest, ) (*pdumppb.DeleteConfigResponse, error)
DeleteConfig removes a packet capture configuration.
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. This function establishes a continuous stream of packet data by:
- Validating the target module (name)
- Retrieving and cloning the ring buffer configuration for safe concurrent access
- Spawning ring buffer readers that continuously monitor shared memory
- Forwarding captured packet records to the gRPC stream
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 (signaled via m.quitCh)
- An error occurs while sending a packet record on the stream
- The configuration of this module is updated (updateModuleConfig terminates matching readers)
Note: Ring buffer readers operate on a cloned configuration to ensure thread safety and prevent interference between concurrent ReadDump requests.
func (*PdumpService) ReclaimDeferred ¶
func (m *PdumpService) ReclaimDeferred()
ReclaimDeferred retries every deferred config, dropping the ones whose generations have drained and keeping the rest deferred. It is the reclamation handler for this module's superseded configs; the service itself runs it after each successful publish, and anything else may call it at any time.
func (*PdumpService) SetConfig ¶
func (m *PdumpService) SetConfig( ctx context.Context, request *pdumppb.SetConfigRequest, ) (*pdumppb.SetConfigResponse, error)
SetConfig updates or creates packet capture configuration. Supports partial updates via UpdateMask.
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 signals a graceful shutdown to all active ReadDump streams.
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.