Skip to content

Commit

Permalink
Add support to load Tracing and LSM programs
Browse files Browse the repository at this point in the history
Signed-off-by: Anastasios Papagiannis <tasos.papagiannnis@gmail.com>
  • Loading branch information
tpapagian authored and kkourt committed May 4, 2023
1 parent ab9d0b6 commit 9e19339
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions pkg/sensors/program/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,46 @@ func NoAttach(load *Program) AttachFunc {
}
}

func TracingAttach(load *Program) AttachFunc {
return func(prog *ebpf.Program, spec *ebpf.ProgramSpec) (unloader.Unloader, error) {
linkFn := func() (link.Link, error) {
return link.AttachTracing(link.TracingOptions{
Program: prog,
})
}
lnk, err := linkFn()
if err != nil {
return nil, fmt.Errorf("attaching '%s' failed: %w", spec.Name, err)
}
return &unloader.RelinkUnloader{
UnloadProg: unloader.PinUnloader{Prog: prog}.Unload,
IsLinked: true,
Link: lnk,
RelinkFn: linkFn,
}, nil
}
}

func LSMAttach(load *Program) AttachFunc {
return func(prog *ebpf.Program, spec *ebpf.ProgramSpec) (unloader.Unloader, error) {
linkFn := func() (link.Link, error) {
return link.AttachLSM(link.LSMOptions{
Program: prog,
})
}
lnk, err := linkFn()
if err != nil {
return nil, fmt.Errorf("attaching '%s' failed: %w", spec.Name, err)
}
return &unloader.RelinkUnloader{
UnloadProg: unloader.PinUnloader{Prog: prog}.Unload,
IsLinked: true,
Link: lnk,
RelinkFn: linkFn,
}, nil
}
}

func MultiKprobeAttach(load *Program) AttachFunc {
return func(prog *ebpf.Program, spec *ebpf.ProgramSpec) (unloader.Unloader, error) {
data, ok := load.AttachData.(*MultiKprobeAttachData)
Expand Down Expand Up @@ -248,6 +288,14 @@ func LoadMultiKprobeProgram(bpfDir, mapDir string, load *Program, verbose int) e
return loadProgram(bpfDir, []string{mapDir}, load, MultiKprobeAttach(load), ci, verbose)
}

func LoadTracingProgram(bpfDir, mapDir string, load *Program, verbose int) error {
return loadProgram(bpfDir, []string{mapDir}, load, TracingAttach(load), nil, verbose)
}

func LoadLSMProgram(bpfDir, mapDir string, load *Program, verbose int) error {
return loadProgram(bpfDir, []string{mapDir}, load, LSMAttach(load), nil, verbose)
}

func slimVerifierError(errStr string) string {
// The error is potentially up to 'verifierLogBufferSize' bytes long,
// and most of it is not interesting. For a user-friendly output, we'll
Expand Down

0 comments on commit 9e19339

Please sign in to comment.