-
Notifications
You must be signed in to change notification settings - Fork 1
/
attach_helpers.go
53 lines (48 loc) · 1.02 KB
/
attach_helpers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"github.com/cilium/ebpf"
"github.com/cilium/ebpf/link"
)
type CalledContext struct {
Pc uint64
By uint64
SkbLocation
}
type SkbLocation struct {
OnStack bool
OffsetFromBp uint64
Register uint8
}
func attachBpfHelpers(prog *ebpf.Program, locationMap *ebpf.Map) (err error) {
helpers, err := findBpfHelpers()
if err != nil {
return
}
for name, contexts := range helpers {
kp, err := link.Kprobe(name, prog, nil)
if err != nil {
return err
}
defer kp.Close()
for _, ctx := range contexts {
called := struct {
Pc uint64
By uint64
}{
Pc: ctx.Pc,
By: ctx.By,
}
locationMap.Update(called, ctx.SkbLocation, ebpf.UpdateNoExist)
}
}
return
}
// TODO: use cilium/ebpf to list programs
// - bpftool -j p
// - cat /proc/kallsyms
// - bpftool -j p d i $id
// - find all call insns, calc target function, figure out pc, by, name
// - anal %rdi location, figure out its SkbLocation
func findBpfHelpers() (helpers map[string][]CalledContext, err error) {
return
}