Skip to content

Commit 01f6daa

Browse files
committed
add support for iterator programs
1 parent e75db0b commit 01f6daa

2 files changed

Lines changed: 28 additions & 4 deletions

File tree

probe.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"time"
1111

1212
"github.com/cilium/ebpf"
13+
"github.com/cilium/ebpf/link"
1314
"github.com/vishvananda/netlink"
1415
"golang.org/x/sys/unix"
1516

@@ -576,6 +577,22 @@ func (p *Probe) attach() error {
576577
return nil
577578
}
578579

580+
func (p *Probe) Iterator() (io.ReadCloser, error) {
581+
p.stateLock.RLock()
582+
defer p.stateLock.RUnlock()
583+
if p.state <= paused || !p.Enabled {
584+
return nil, ErrManagerNotStarted
585+
}
586+
if p.programSpec.AttachType != ebpf.AttachTraceIter {
587+
return nil, fmt.Errorf("invalid program attach type %s", p.programSpec.AttachType)
588+
}
589+
it, ok := p.progLink.(*link.Iter)
590+
if !ok {
591+
return nil, fmt.Errorf("invalid program attach type %T", p.progLink)
592+
}
593+
return it.Open()
594+
}
595+
579596
// cleanupProgramSpec - Cleans up the internal ProgramSpec attribute to free up some memory
580597
func (p *Probe) cleanupProgramSpec() {
581598
if p.KeepProgramSpec {

tracing.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,22 @@ package manager
33
import (
44
"fmt"
55

6+
"github.com/cilium/ebpf"
67
"github.com/cilium/ebpf/link"
78
)
89

910
func (p *Probe) attachTracing() error {
1011
var err error
11-
p.progLink, err = link.AttachTracing(link.TracingOptions{
12-
Program: p.program,
13-
AttachType: p.programSpec.AttachType,
14-
})
12+
if p.programSpec.AttachType == ebpf.AttachTraceIter {
13+
p.progLink, err = link.AttachIter(link.IterOptions{
14+
Program: p.program,
15+
})
16+
} else {
17+
p.progLink, err = link.AttachTracing(link.TracingOptions{
18+
Program: p.program,
19+
AttachType: p.programSpec.AttachType,
20+
})
21+
}
1522
if err != nil {
1623
return fmt.Errorf("link tracing: %w", err)
1724
}

0 commit comments

Comments
 (0)