From 5ebb3e08fdf95e56bc7f8652d83fb863c70dd862 Mon Sep 17 00:00:00 2001 From: Tristan d'Audibert Date: Wed, 20 Nov 2024 16:56:49 +0100 Subject: [PATCH] [generickprobe.go] Add ExtractParam/OverwriteType usage for kprobes Add very similar code as in `genericlsm.go` file to handle those params. In a future commit, a refactoring should be acheived to avoid code redundant code with `genericlsm.go` Signed-off-by: Tristan d'Audibert --- pkg/sensors/tracing/generickprobe.go | 30 ++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/pkg/sensors/tracing/generickprobe.go b/pkg/sensors/tracing/generickprobe.go index 21a3bbf1dc9..4a0df9f7e51 100644 --- a/pkg/sensors/tracing/generickprobe.go +++ b/pkg/sensors/tracing/generickprobe.go @@ -692,6 +692,7 @@ func addKprobe(funcName string, instance int, f *v1alpha1.KProbeSpec, in *addKpr var setRetprobe bool var argRetprobe *v1alpha1.KProbeArg var argsBTFSet [api.MaxArgsSupported]bool + var allArgsBtfChilds [api.EventConfigMaxArgs][api.MaxBtfArgChildDepth]api.ConfigBtfArgChild errFn := func(err error) (idtable.EntryID, error) { return idtable.UninitializedEntryID, err @@ -758,6 +759,34 @@ func addKprobe(funcName string, instance int, f *v1alpha1.KProbeSpec, in *addKpr argType = gt.GenericTypeFromString(a.Type) } + if a.ExtractParam != "" && j < api.EventConfigMaxArgs { + allArgsBtfChilds[j] = [api.MaxBtfArgChildDepth]api.ConfigBtfArgChild{} + spec, err := btf.NewBTF() + if err != nil { + return errFn(fmt.Errorf("Unable to load BTF file")) + } + + partialPath := strings.Split(a.ExtractParam, ".") + if len(partialPath) > api.MaxBtfArgChildDepth { + return errFn(fmt.Errorf("Exausted research in BTF for type %s. The maximum depth allowed is %d", a.Type, api.MaxBtfArgChildDepth)) + } + + rootType, err := spec.AnyTypeByName(a.Type) + if err != nil { + return errFn(fmt.Errorf("Type %s has not been found in BTF", a.Type)) + } + lastChild, err := btf.FindNextBTFType(&allArgsBtfChilds[j], rootType, &partialPath, 0) + if err != nil { + return errFn(err) + } + + if a.OverwriteType != "" { + argType = gt.GenericTypeFromString(a.OverwriteType) + } else { + argType = gt.GenericTypeFromBTF(*lastChild) + } + } + if argType == gt.GenericInvalidType { return errFn(fmt.Errorf("Arg(%d) type '%s' unsupported", j, a.Type)) } @@ -781,6 +810,7 @@ func addKprobe(funcName string, instance int, f *v1alpha1.KProbeSpec, in *addKpr return errFn(fmt.Errorf("Error add arg: ArgType %s Index %d out of bounds", a.Type, int(a.Index))) } + config.BtfArgChild = allArgsBtfChilds config.Arg[a.Index] = int32(argType) config.ArgM[a.Index] = uint32(argMValue)