Skip to content

Commit

Permalink
tracing: add spec options to policyInfo
Browse files Browse the repository at this point in the history
Spec options are policy-wide, so place them in policy info. They will be
used in a subsequent patch to configure the policy mode. No functional
changes.

Signed-off-by: Kornilios Kourtis <[email protected]>
  • Loading branch information
kkourt committed Feb 13, 2025
1 parent dcd1fee commit a3aa5df
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
8 changes: 2 additions & 6 deletions pkg/sensors/tracing/generickprobe.go
Original file line number Diff line number Diff line change
Expand Up @@ -601,16 +601,11 @@ func createGenericKprobeSensor(
kprobes := spec.KProbes
lists := spec.Lists

specOpts, err := getSpecOptions(spec.Options)
if err != nil {
return nil, fmt.Errorf("failed to get spec options: %s", err)
}

// use multi kprobe only if:
// - it's not disabled by spec option
// - it's not disabled by command line option
// - there's support detected
if !specOpts.DisableKprobeMulti {
if !polInfo.specOpts.DisableKprobeMulti {
useMulti = !option.Config.DisableKprobeMulti && bpf.HasKprobeMulti()
}

Expand Down Expand Up @@ -655,6 +650,7 @@ func createGenericKprobeSensor(
}
}

var err error
if useMulti {
progs, maps, err = createMultiKprobeSensor(polInfo, ids, has)
} else {
Expand Down
7 changes: 1 addition & 6 deletions pkg/sensors/tracing/genericuprobe.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,19 +252,14 @@ func createGenericUprobeSensor(
var ids []idtable.EntryID
var err error

options, err := getSpecOptions(spec.Options)
if err != nil {
return nil, fmt.Errorf("failed to set options: %s", err)
}

in := addUprobeIn{
sensorPath: name,
policyName: polInfo.name,

// use multi kprobe only if:
// - it's not disabled by spec option
// - there's support detected
useMulti: !options.DisableUprobeMulti && bpf.HasUprobeMulti(),
useMulti: !polInfo.specOpts.DisableUprobeMulti && bpf.HasUprobeMulti(),
}

for _, uprobe := range spec.UProbes {
Expand Down
16 changes: 13 additions & 3 deletions pkg/sensors/tracing/policyhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,30 @@ type policyInfo struct {
policyID policyfilter.PolicyID
customHandler eventhandler.Handler
maps map[string]struct{}
specOpts *specOptions
}

func newPolicyInfo(
policy tracingpolicy.TracingPolicy,
policyID policyfilter.PolicyID,
) *policyInfo {
) (*policyInfo, error) {
namespace := ""
if tpn, ok := policy.(tracingpolicy.TracingPolicyNamespaced); ok {
namespace = tpn.TpNamespace()
}

opts, err := getSpecOptions(policy.TpSpec().Options)
if err != nil {
return nil, err
}
return &policyInfo{
name: policy.TpName(),
namespace: namespace,
policyID: policyID,
customHandler: eventhandler.GetCustomEventhandler(policy),
maps: map[string]struct{}{},
}
specOpts: opts,
}, nil
}

func (pi *policyInfo) mapBuilder(name string, prog *program.Program) *program.Map {
Expand Down Expand Up @@ -77,7 +84,10 @@ func (h policyHandler) PolicyHandler(
return nil, errors.New("tracing policies with multiple sections of kprobes, tracepoints, lsm hooks, or uprobes are currently not supported")
}

polInfo := newPolicyInfo(policy, policyID)
polInfo, err := newPolicyInfo(policy, policyID)
if err != nil {
return nil, fmt.Errorf("failed to parse options: %w", err)
}

if len(spec.KProbes) > 0 {
name := "generic_kprobe"
Expand Down

0 comments on commit a3aa5df

Please sign in to comment.