Skip to content

Commit

Permalink
link: Add support to attach kprobe multi as session
Browse files Browse the repository at this point in the history
Signed-off-by: Jiri Olsa <[email protected]>
  • Loading branch information
olsajiri committed Dec 13, 2024
1 parent 9789f47 commit f5c6b7a
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
5 changes: 3 additions & 2 deletions attachtype_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion link/kprobe_multi.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ type KprobeMultiOptions struct {
// Each Cookie is assigned to the Symbol or Address specified at the
// corresponding slice index.
Cookies []uint64

// Probe is attach as session with BPF_TRACE_KPROBE_SESSION attach type
Session bool
}

// KprobeMulti attaches the given eBPF program to the entry point of a given set
Expand Down Expand Up @@ -82,9 +85,14 @@ func kprobeMulti(prog *ebpf.Program, opts KprobeMultiOptions, flags uint32) (Lin
return nil, fmt.Errorf("Cookies must be exactly Symbols or Addresses in length: %w", errInvalidInput)
}

attachType := sys.BPF_TRACE_KPROBE_MULTI
if opts.Session {
attachType = sys.BPF_TRACE_KPROBE_SESSION
}

attr := &sys.LinkCreateKprobeMultiAttr{
ProgFd: uint32(prog.FD()),
AttachType: sys.BPF_TRACE_KPROBE_MULTI,
AttachType: attachType,
KprobeMultiFlags: flags,
}

Expand Down
14 changes: 14 additions & 0 deletions link/kprobe_multi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,17 @@ func TestKprobeMultiProgramCall(t *testing.T) {
func TestHaveBPFLinkKprobeMulti(t *testing.T) {
testutils.CheckFeatureTest(t, haveBPFLinkKprobeMulti)
}

func TestKprobeSession(t *testing.T) {
testutils.SkipIfNotSupported(t, haveBPFLinkKprobeMulti())

prog := mustLoadProgram(t, ebpf.Kprobe, ebpf.AttachTraceKprobeSession, "")

km, err := KprobeMulti(prog, KprobeMultiOptions{Symbols: kprobeMultiSyms, Session: true})
if err != nil {
t.Fatal(err)
}
defer km.Close()

testLink(t, km, prog)
}
1 change: 1 addition & 0 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ const (
AttachSkReuseportSelectOrMigrate = AttachType(sys.BPF_SK_REUSEPORT_SELECT_OR_MIGRATE)
AttachPerfEvent = AttachType(sys.BPF_PERF_EVENT)
AttachTraceKprobeMulti = AttachType(sys.BPF_TRACE_KPROBE_MULTI)
AttachTraceKprobeSession = AttachType(sys.BPF_TRACE_KPROBE_SESSION)
AttachLSMCgroup = AttachType(sys.BPF_LSM_CGROUP)
AttachStructOps = AttachType(sys.BPF_STRUCT_OPS)
AttachNetfilter = AttachType(sys.BPF_NETFILTER)
Expand Down

0 comments on commit f5c6b7a

Please sign in to comment.