selectors

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: Apache-2.0 Imports: 32 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	StateValueSize = 8

	// Mirrored by STATE_OP_* in bpf/process/types/basic.h
	StateOpSet    = 0
	StateOpDelete = 1

	ActionTypeInvalid = -1
	ActionTypePost    = 0
	// ActionTypeFollowFd                    = 1 deprecated
	ActionTypeSigKill = 2
	// ActionTypeUnfollowFd                  = 3 deprecated
	ActionTypeOverride = 4
	// ActionTypeCopyFd                      = 5 deprecated
	ActionTypeGetUrl                      = 6
	ActionTypeDnsLookup                   = 7
	ActionTypeNoPost                      = 8
	ActionTypeSignal                      = 9
	ActionTypeTrackSock                   = 10
	ActionTypeUntrackSock                 = 11
	ActionTypeNotifyEnforcer              = 12
	ActionTypeCleanupEnforcerNotification = 13
	ActionTypeSet                         = 14
	ActionTypeUpdateState                 = 15
)
View Source
const (
	ActionRateLimitScopeThread = iota
	ActionRateLimitScopeProcess
	ActionRateLimitScopeGlobal
)
View Source
const (
	SelectorOpGT  = 1
	SelectorOpLT  = 2
	SelectorOpEQ  = 3
	SelectorOpNEQ = 4
	// Pid and Namespace ops
	SelectorOpIn    = 5
	SelectorOpNotIn = 6
	// String ops
	SelectorOpPrefix  = 8
	SelectorOpPostfix = 9
	// Map ops
	SelectorInMap    = 10
	SelectorNotInMap = 11

	SelectorOpMASK = 12

	// socket ops
	SelectorOpSaddr        = 13
	SelectorOpDaddr        = 14
	SelectorOpSport        = 15
	SelectorOpDport        = 16
	SelectorOpProtocol     = 17
	SelectorOpNotSport     = 18
	SelectorOpNotDport     = 19
	SelectorOpSportPriv    = 20
	SelectorOpNotSportPriv = 21
	SelectorOpDportPriv    = 22
	SelectorOpNotDportPriv = 23
	SelectorOpNotSaddr     = 24
	SelectorOpNotDaddr     = 25
	// file ops
	SelectorOpNotPrefix  = 26
	SelectorOpNotPostfix = 27
	// more socket ops
	SelectorOpFamily = 28
	SelectorOpState  = 29
	// capabilities
	SelectorOpCapabilitiesGained = 30
	// range
	SelectorOpInRange    = 31
	SelectorOpNotInRange = 32
	// match string
	SelectorOpSubString        = 33
	SelectorOpSubStringIgnCase = 34
	// CEL expressions translated to BPF
	SelectorOpCelExpr = 35
	// file type
	SelectorOpFileType    = 36
	SelectorOpNotFileType = 37
)
View Source
const (
	// see bpf/process/types/basic.h MAX_SELECTORS
	MaxSelectors = 5

	StringMapsNumSubMaps      = 11
	StringMapsNumSubMapsSmall = 8
	MaxStringMapsSize         = 4096 + 2
	StringPrefixMaxLength     = 256
	StringPostfixMaxLength    = 128
	// StringPostfixMaxMatchLengthSmall is the postfix match length that the
	// BPF programs support on kernels without large BPF program support. Keep
	// in sync with STRING_POSTFIX_MAX_MATCH_LENGTH in bpf/process/string_maps.h.
	StringPostfixMaxMatchLengthSmall = 88

	StringMapSize7a = 512

	SubstringMapEntries = 100
)
View Source
const ArgsInRegisters = 6 // Number of arguments passed by register per System V AMD64 ABI
View Source
const KernelBufferSize = 4096
View Source
const (
	// maximum number of CelExpr functions supported in the datapath
	MaxCelExprFunctions = 8 // see bpf/process/cel_expr.h
)

Variables

View Source
var (
	StringMapsSizes = [StringMapsNumSubMaps]int{
		stringMapSize0,
		stringMapSize1,
		stringMapSize2,
		stringMapSize3,
		stringMapSize4,
		stringMapSize5,
		stringMapSize6,
		stringMapSize7,
		stringMapSize8,
		stringMapSize9,
		stringMapSize10,
	}
)

Functions

func ActionTypeFromString added in v0.10.0

func ActionTypeFromString(action string) int32

func AdvanceSelectorLength

func AdvanceSelectorLength(k *KernelSelectorData) uint32

func ArgPostfixSelectorValue added in v1.0.0

func ArgPostfixSelectorValue(v string, removeNul bool) ([]byte, uint32)

func ArgSelectorValue

func ArgSelectorValue(v string) ([]byte, uint32)

func ArgStringSelectorValue added in v1.0.0

func ArgStringSelectorValue(v string, removeNul bool) ([MaxStringMapsSize]byte, int, error)

func CelExprFuncName added in v1.7.0

func CelExprFuncName(idx int) string

func CleanupKernelSelectorState added in v1.5.0

func CleanupKernelSelectorState(state *KernelSelectorState) error

func CountOverrideArgNewSymbolAddrOffset added in v1.8.0

func CountOverrideArgNewSymbolAddrOffset(selectors []v1alpha1.KProbeSelector) int

CountOverrideArgNewSymbolAddrOffset returns the highest number of argNewSymbol, argNewAddr and argNewOffset set on a single Override action, across all selectors.

func GetCurrentOffset added in v0.10.0

func GetCurrentOffset(k *KernelSelectorData) uint32

func HasEnforcementAction added in v1.7.0

func HasEnforcementAction(selectors []v1alpha1.KProbeSelector) bool

func HasEnforcerAction added in v1.8.0

func HasEnforcerAction(selectors []v1alpha1.KProbeSelector) bool

HasEnforcerAction returns true if any selector has an action that needs the enforcer sensor. Unlike HasNotifyEnforcerAction it also covers CleanupEnforcerNotification and matchReturnActions.

func HasFilter added in v1.5.0

func HasFilter(selectors []v1alpha1.KProbeSelector, index uint32) bool

func HasGetUrlOrDnsLookup added in v1.7.1

func HasGetUrlOrDnsLookup(selectors []v1alpha1.KProbeSelector) bool

func HasNotifyEnforcerAction added in v1.6.0

func HasNotifyEnforcerAction(selectors []v1alpha1.KProbeSelector) bool

HasNotifyEnforcerAction returns true if any selector has a NotifyEnforcer action

func HasOperator added in v1.7.0

func HasOperator(selectors []v1alpha1.KProbeSelector, op uint32) bool

func HasOverride

func HasOverride(selectors []v1alpha1.KProbeSelector) bool

func HasRateLimit added in v1.6.0

func HasRateLimit(selectors []v1alpha1.KProbeSelector) bool

func HasSelector added in v1.7.0

func HasSelector(spec *v1alpha1.KProbeSpec) bool

func HasSet added in v1.6.0

func HasSet(selectors []v1alpha1.KProbeSelector) bool

func HasSetArgIndexValue added in v1.8.0

func HasSetArgIndexValue(selectors []v1alpha1.KProbeSelector) (bool, uint32, uint64)

func HasSigkillAction added in v1.0.0

func HasSigkillAction(kspec *v1alpha1.KProbeSpec) bool

func HasSockTrack added in v1.7.0

func HasSockTrack(spec *v1alpha1.KProbeSpec) bool

func HasStackTrace added in v1.6.0

func HasStackTrace(selectors []v1alpha1.KProbeSelector) bool

func InitKernelReturnSelectors added in v1.1.0

func InitKernelReturnSelectors(selectors []v1alpha1.KProbeSelector, returnArg *v1alpha1.KProbeArg, actionArgTable *idtable.Table) ([KernelBufferSize]byte, error)

func InitKernelSelectors

func InitKernelSelectors(selectors []v1alpha1.KProbeSelector, args []v1alpha1.KProbeArg, data []v1alpha1.KProbeArg, actionArgTable *idtable.Table) ([KernelBufferSize]byte, error)

The byte array storing the selector configuration has the following format array := [N][S1_off][S2_off]...[SN_off][S1][S2][...][SN]

N: is the number of selectors (u32)
Sx_off: is the relative offset of  selector x (diff of Sx to Sx_off)
Sx: holds the data for the selector

Each selector x starts with its length in bytes, and then stores a number of sections for the different matchers. Each section will typically starts with its length in bytes.

Sx := [length]

[matchPIDs]
[matchNamespaces]
[matchCapabilities]
[matchNamespaceChanges]
[matchCapabilityChanges]
[matchStates]
[matchCmdArgs]
[matchCallers]
[matchArgs]
[matchActions]

matchPIDs := [length][PID1][PID2]...[PIDn] matchNamespaces := [length][NSx][NSy]...[NSn] matchCapabilities := [length][CAx][CAy]...[CAn] matchNamespaceChanges := [length][NCx][NCy]...[NCn] matchCapabilityChanges := [length][CAx][CAy]...[CAn] matchStates := [length][STATEx]...[STATEn] matchCmdArgs := [length][CMDARGx][CMDARGy]...[CMDARGn] matchCallers := [length u32][BuildIDLength u32][BuildID1 [20]byte]...[BuildIDn][CAL1]...[CALn] matchArgs := [length][ARGx][ARGy]...[ARGn] PIDn := [op][flags][nValues][v1]...[vn] Argn := [index][op][valueGen] NSn := namespace[op][valueInt] NCn := [op][valueInt] CAn := [type][op][namespacecap][valueInt] CALn := [depth uint32][BuildIDRef uint32][startRange uint64][endRange uint64] STATEn := [stateID u32][op u32][valueInt u64] valueGen := [type][len][v] valueInt := [len][v]

For some examples, see kernel_test.go

func MatchActionSigKill

func MatchActionSigKill(spec any) bool

func MatchAllLabelSelector added in v1.8.0

func MatchAllLabelSelector(s *slimv1.LabelSelector) bool

func MatchNothingLabelSelector added in v1.8.0

func MatchNothingLabelSelector(s *slimv1.LabelSelector) bool

func ParseMatchAction added in v0.9.0

func ParseMatchAction(k *KernelSelectorState, action *v1alpha1.ActionSelector, actionArgTable *idtable.Table, selIdx int, args []v1alpha1.KProbeArg, data []v1alpha1.KProbeArg, stateIDs map[string]uint32) error

func ParseMatchActions added in v0.9.0

func ParseMatchActions(k *KernelSelectorState, actions []v1alpha1.ActionSelector, actionArgTable *idtable.Table, selIdx int, args []v1alpha1.KProbeArg, data []v1alpha1.KProbeArg, stateIDs map[string]uint32) error

func ParseMatchArg added in v0.9.0

func ParseMatchArg(k *KernelSelectorState, arg *v1alpha1.ArgSelector, sig []v1alpha1.KProbeArg) error

func ParseMatchArgs added in v0.9.0

func ParseMatchArgs(
	k *KernelSelectorState,
	matchArgs []v1alpha1.ArgSelector, matchData []v1alpha1.ArgSelector,
	matchCEL *v1alpha1.CELExprSelector,
	args []v1alpha1.KProbeArg, data []v1alpha1.KProbeArg,
) error

func ParseMatchBinaries added in v0.9.0

func ParseMatchBinaries(k *KernelSelectorState, binaries []v1alpha1.BinarySelector, selIdx int, selector genericMatchBinariesSelector) error

func ParseMatchBinary added in v0.9.0

func ParseMatchBinary(k *KernelSelectorState, b *v1alpha1.BinarySelector, selIdx int, selectorType genericMatchBinariesSelector) error

func ParseMatchCaller added in v1.8.0

func ParseMatchCaller(k *KernelSelectorState, caller *v1alpha1.UserCallerSelector,
	buildIDRef uint32, elfFile *telf.SafeELFFile, path string) error

func ParseMatchCallers added in v1.8.0

func ParseMatchCallers(k *KernelSelectorState, matchUserCallers []v1alpha1.UserCallerSelector, binaryPath string) error

func ParseMatchCapabilities added in v0.9.0

func ParseMatchCapabilities(k *KernelSelectorState, actions []v1alpha1.CapabilitiesSelector) error

func ParseMatchCapabilityChanges added in v0.9.0

func ParseMatchCapabilityChanges(k *KernelSelectorState, actions []v1alpha1.CapabilitiesSelector) error

func ParseMatchCaps added in v0.9.0

func ParseMatchCaps(k *KernelSelectorState, action *v1alpha1.CapabilitiesSelector) error

func ParseMatchCmdArg added in v1.8.0

func ParseMatchCmdArg(k *KernelSelectorState, cmdArg *v1alpha1.CmdArgSelector) error

func ParseMatchCmdArgs added in v1.8.0

func ParseMatchCmdArgs(k *KernelSelectorState, matchCmdArgs []v1alpha1.CmdArgSelector) error

func ParseMatchData added in v1.6.0

func ParseMatchData(k *KernelSelectorState, arg *v1alpha1.ArgSelector, data []v1alpha1.KProbeArg, base uint32) error

func ParseMatchNamespace added in v0.9.0

func ParseMatchNamespace(k *KernelSelectorState, action *v1alpha1.NamespaceSelector) error

func ParseMatchNamespaceChange added in v0.9.0

func ParseMatchNamespaceChange(k *KernelSelectorState, action *v1alpha1.NamespaceChangesSelector) error

func ParseMatchNamespaceChanges added in v0.9.0

func ParseMatchNamespaceChanges(k *KernelSelectorState, actions []v1alpha1.NamespaceChangesSelector) error

func ParseMatchNamespaces added in v0.9.0

func ParseMatchNamespaces(k *KernelSelectorState, actions []v1alpha1.NamespaceSelector) error

func ParseMatchPid added in v0.9.0

func ParseMatchPid(k *KernelSelectorState, pid *v1alpha1.PIDSelector) error

func ParseMatchPids added in v0.9.0

func ParseMatchPids(k *KernelSelectorState, matchPids []v1alpha1.PIDSelector) error

func ParseMatchStates added in v1.8.0

func ParseMatchStates(k *KernelSelectorState, states []v1alpha1.StateSelector, stateIDs map[string]uint32) error

func ParseMatchWorkloads added in v1.8.0

func ParseMatchWorkloads(k *KernelSelectorState, workload *v1alpha1.WorkloadsSelector, selIdx int) error

func SelectorOp added in v0.9.0

func SelectorOp(op string) (uint32, error)

func WriteSelectorByteArray

func WriteSelectorByteArray(k *KernelSelectorData, b []byte, size uint32)

func WriteSelectorInt32

func WriteSelectorInt32(k *KernelSelectorData, v int32)

func WriteSelectorInt64

func WriteSelectorInt64(k *KernelSelectorData, v int64)

func WriteSelectorLength

func WriteSelectorLength(k *KernelSelectorData, loff uint32)

WriteSelectorLength and WriteSelectorOffsetUint32 backpatch a uint32 previously reserved by AdvanceSelectorLength, so loff always refers to bytes already appended to e.

func WriteSelectorOffsetUint32 added in v0.10.0

func WriteSelectorOffsetUint32(k *KernelSelectorData, loff uint32, val uint32)

func WriteSelectorUint32

func WriteSelectorUint32(k *KernelSelectorData, v uint32)

func WriteSelectorUint64

func WriteSelectorUint64(k *KernelSelectorData, v uint64)

Types

type ActionArgEntry added in v0.8.4

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

Action argument table entry (for URL and FQDN arguments)

func (*ActionArgEntry) GetArg added in v0.8.4

func (g *ActionArgEntry) GetArg() string

func (*ActionArgEntry) SetID added in v0.8.4

func (g *ActionArgEntry) SetID(id idtable.EntryID)

type CelExprFunctions added in v1.7.0

type CelExprFunctions []asm.Instructions

CelExprFunctions holds all the generated instructions for the CEL expressions

func (CelExprFunctions) RewriteProg added in v1.7.0

func (cefs CelExprFunctions) RewriteProg(prog *ebpf.ProgramSpec) error

type KernelLPMTrie4 added in v1.0.0

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

type KernelLPMTrie6 added in v1.0.0

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

type KernelLPMTrieStringPostfix added in v1.0.0

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

type KernelLPMTrieStringPrefix added in v1.0.0

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

type KernelSelectorArgs added in v1.6.0

type KernelSelectorArgs struct {
	Selectors      []v1alpha1.KProbeSelector
	Args           []v1alpha1.KProbeArg
	Data           []v1alpha1.KProbeArg
	ActionArgTable *idtable.Table
	ListReader     ValueReader
	Maps           *KernelSelectorMaps
	IsUprobe       bool
	UprobeID       int
	// For Override argNew{Symbol,Addr,Offset} this will hold
	// the instruction pointer delta of each selector, keyed by
	// selector index, that will be stored by ParseMatchAction().
	OverrideActionIPDeltas map[int]int64
	CelExprs               *CelExprFunctions
	// BinaryPath is used as default binary path for matchCaller selectors.
	BinaryPath string
	StateIDs   map[string]uint32
}

type KernelSelectorData added in v1.1.0

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

type KernelSelectorMaps added in v1.0.0

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

type KernelSelectorState

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

func InitKernelReturnSelectorState added in v1.1.0

func InitKernelReturnSelectorState(selectors []v1alpha1.KProbeSelector, returnArg *v1alpha1.KProbeArg,
	actionArgTable *idtable.Table, listReader ValueReader, maps *KernelSelectorMaps, stateIDs map[string]uint32) (*KernelSelectorState, error)

func InitKernelSelectorState added in v0.8.3

func InitKernelSelectorState(args *KernelSelectorArgs) (*KernelSelectorState, error)

func NewKernelSelectorState added in v0.9.0

func NewKernelSelectorState(
	listReader ValueReader,
	maps *KernelSelectorMaps,
	isUprobe bool,
	uprobeID int,
	overrideActionIPDeltas map[int]int64,
	celExprs *CelExprFunctions,
) *KernelSelectorState

func (*KernelSelectorState) AddMatchBinaries added in v1.1.0

func (k *KernelSelectorState) AddMatchBinaries(i int, sel MatchBinariesSelectorOptions)

func (*KernelSelectorState) Addr4Maps added in v0.11.0

func (k *KernelSelectorState) Addr4Maps() []map[KernelLPMTrie4]struct{}

func (*KernelSelectorState) Addr4MapsMaxEntries added in v0.11.0

func (k *KernelSelectorState) Addr4MapsMaxEntries() int

Addr4MapsMaxEntries returns the maximum entries over all maps

func (*KernelSelectorState) Addr6Maps added in v0.11.0

func (k *KernelSelectorState) Addr6Maps() []map[KernelLPMTrie6]struct{}

func (*KernelSelectorState) Addr6MapsMaxEntries added in v0.11.0

func (k *KernelSelectorState) Addr6MapsMaxEntries() int

Addr6MapsMaxEntries returns the maximum entries over all maps

func (*KernelSelectorState) CelExprFunctions added in v1.7.0

func (k *KernelSelectorState) CelExprFunctions() *CelExprFunctions

func (*KernelSelectorState) CopyToFixedBuffer added in v1.8.0

func (k *KernelSelectorState) CopyToFixedBuffer() [KernelBufferSize]byte

func (*KernelSelectorState) Destroyed added in v1.8.0

func (k *KernelSelectorState) Destroyed() bool

func (KernelSelectorState) MatchBinaries added in v1.1.0

func (KernelSelectorState) MatchBinariesPaths added in v1.1.0

func (k KernelSelectorState) MatchBinariesPaths() map[int][][processapi.BINARY_PATH_MAX_LEN]byte

func (*KernelSelectorState) MatchBinariesPathsMaxEntries added in v1.1.0

func (k *KernelSelectorState) MatchBinariesPathsMaxEntries() int

MatchBinariesPathsMaxEntries returns the maximum entries over all maps

func (KernelSelectorState) MatchWorkloadIDs added in v1.8.0

func (k KernelSelectorState) MatchWorkloadIDs() map[int]policyfilter.PolicyID

func (*KernelSelectorState) Regs added in v1.6.0

func (*KernelSelectorState) StringMaps added in v1.0.0

func (k *KernelSelectorState) StringMaps(subMap int) []map[[MaxStringMapsSize]byte]struct{}

func (*KernelSelectorState) StringMapsMaxEntries added in v1.0.0

func (k *KernelSelectorState) StringMapsMaxEntries(subMap int) int

StringMapsMaxEntries returns the maximum entries over all maps inside a particular map of map

func (*KernelSelectorState) StringPostfixMaps added in v1.0.0

func (k *KernelSelectorState) StringPostfixMaps() []map[KernelLPMTrieStringPostfix]struct{}

func (*KernelSelectorState) StringPostfixMapsMaxEntries added in v1.0.0

func (k *KernelSelectorState) StringPostfixMapsMaxEntries() int

StringPostfixMapsMaxEntries returns the maximum entries over all maps

func (*KernelSelectorState) StringPrefixMaps added in v1.0.0

func (k *KernelSelectorState) StringPrefixMaps() []map[KernelLPMTrieStringPrefix]struct{}

func (*KernelSelectorState) StringPrefixMapsMaxEntries added in v1.0.0

func (k *KernelSelectorState) StringPrefixMapsMaxEntries() int

StringPrefixMapsMaxEntries returns the maximum entries over all maps

func (*KernelSelectorState) SubStrings added in v1.7.0

func (k *KernelSelectorState) SubStrings() []string

func (*KernelSelectorState) UprobeRegsMapID added in v1.8.0

func (k *KernelSelectorState) UprobeRegsMapID(selIdx int) uint32

func (*KernelSelectorState) Usage added in v1.8.0

func (*KernelSelectorState) ValueMaps added in v0.8.3

func (k *KernelSelectorState) ValueMaps() []ValueMap

func (*KernelSelectorState) ValueMapsMaxEntries added in v0.11.0

func (k *KernelSelectorState) ValueMapsMaxEntries() int

ValueMapsMaxEntries returns the maximum entries over all maps

func (*KernelSelectorState) WriteMatchBinariesPath added in v1.1.0

func (k *KernelSelectorState) WriteMatchBinariesPath(selectorID int, path string)

type MatchBinariesSelectorOptions added in v1.1.0

type MatchBinariesSelectorOptions struct {
	Op    uint32
	MapID uint32
	// matchBinaries set for the selector
	MBSetID uint32
}

type SelectorStringMaps added in v1.0.0

type SelectorStringMaps [StringMapsNumSubMaps]map[[MaxStringMapsSize]byte]struct{}

type SelectorUsage added in v1.8.0

type SelectorUsage struct {
	MatchPIDs              bool
	MatchNamespaces        bool
	MatchCapabilities      bool
	MatchNamespaceChanges  bool
	MatchCapabilityChanges bool
	MatchBinaries          bool
	MatchParentBinaries    bool
	MatchCmdArgs           bool
	MatchWorkloads         bool
	MatchCEL               bool
	MatchArgFilters        bool
	MatchUserCallers       bool
	MatchStates            bool
}

type StringMapLists added in v1.0.0

type StringMapLists [StringMapsNumSubMaps][]map[[MaxStringMapsSize]byte]struct{}

type ValueMap added in v0.11.0

type ValueMap struct {
	Data map[[8]byte]struct{}
}

type ValueReader added in v0.11.0

type ValueReader interface {
	Read(value string, ty uint32) ([]uint32, error)
}

Jump to

Keyboard shortcuts

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