Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions ebpftracer/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"sync"
"sync/atomic"
"time"
"unsafe"

"github.com/cilium/ebpf"
"github.com/cilium/ebpf/link"
Expand Down Expand Up @@ -468,13 +469,11 @@ func runEventsReader(name string, r *perf.Reader, ch chan<- Event, typ perfMapTy

switch typ {
case perfMapTypeL7Events:
v := &l7Event{}
data := rec.RawSample

if err := binary.Read(bytes.NewBuffer(data), binary.LittleEndian, v); err != nil {
klog.Warningln("failed to read l7 event:", err)
if len(rec.RawSample) < int(unsafe.Sizeof(l7Event{})) {
klog.Warningln("l7 event too short", len(rec.RawSample))
continue
}
v := (*l7Event)(unsafe.Pointer(&rec.RawSample[0]))

// Extract payload data directly from the struct arrays
payloadSize := min(int(v.PayloadSize), len(v.Payload))
Expand Down Expand Up @@ -507,18 +506,18 @@ func runEventsReader(name string, r *perf.Reader, ch chan<- Event, typ perfMapTy
L7Request: req,
}
case perfMapTypeFileEvents:
v := &fileEvent{}
if err := binary.Read(bytes.NewBuffer(rec.RawSample), binary.LittleEndian, v); err != nil {
klog.Warningln("failed to read file event:", err)
if len(rec.RawSample) < int(unsafe.Sizeof(fileEvent{})) {
klog.Warningln("file event too short", len(rec.RawSample))
continue
}
v := (*fileEvent)(unsafe.Pointer(&rec.RawSample[0]))
event = Event{Type: v.Type, Pid: v.Pid, Fd: v.Fd, Mnt: v.Mnt, Log: v.Log > 0}
case perfMapTypeProcEvents:
v := &procEvent{}
if err := binary.Read(bytes.NewBuffer(rec.RawSample), binary.LittleEndian, v); err != nil {
klog.Warningln("failed to read proc event:", err)
if len(rec.RawSample) < int(unsafe.Sizeof(procEvent{})) {
klog.Warningln("proc event too short", len(rec.RawSample))
continue
}
v := (*procEvent)(unsafe.Pointer(&rec.RawSample[0]))
event = Event{Type: v.Type, Reason: EventReason(v.Reason), Pid: v.Pid}
case perfMapTypeTCPEvents:
v := &tcpEvent{}
Expand Down
Loading