-
-
Save slaise/297c5adbc949d133f2ce400b45e00209 to your computer and use it in GitHub Desktop.
caretta notes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://github.com/groundcover-com/caretta/blob/b03437eadacb683c9f4170ccb6f7acd9efeb12af/pkg/tracing/probes.go | |
func LoadProbes() (Probes, *ebpf.Map, error) { | |
objs := bpfObjects{} | |
err := loadBpfObjects(&objs, &ebpf.CollectionOptions{}) | |
if err != nil { | |
var ve *ebpf.VerifierError | |
if errors.As(err, &ve) { | |
fmt.Printf("Verifier Error: %+v\n", ve) | |
} | |
return Probes{}, nil, fmt.Errorf("error loading BPF objects from go-side. %v", err) | |
} | |
log.Printf("BPF objects loaded") | |
// attach a kprobe and tracepoint | |
kp, err := link.Kprobe("tcp_data_queue", objs.bpfPrograms.HandleTcpDataQueue, nil) | |
if err != nil { | |
return Probes{}, nil, fmt.Errorf("error attaching kprobe: %v", err) | |
} | |
log.Printf("Kprobe attached successfully") | |
tp, err := link.Tracepoint("sock", "inet_sock_set_state", objs.bpfPrograms.HandleSockSetState, nil) | |
if err != nil { | |
return Probes{}, nil, fmt.Errorf("error attaching tracepoint: %v", err) | |
} | |
log.Printf("Tracepoint attached successfully") | |
return Probes{ | |
Kprobe: kp, | |
Tracepoint: tp, | |
BpfObjs: objs, | |
}, objs.Connections, nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment