Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(prog): Add autoattach api #406

Merged
merged 1 commit into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions prog.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ func (p *BPFProg) SetAutoload(autoload bool) error {
return nil
}

func (p *BPFProg) SetAutoattach(autoload bool) {
C.bpf_program__set_autoattach(p.prog, C.bool(autoload))
}

func (p *BPFProg) Autoattach() bool {
return bool(C.bpf_program__autoattach(p.prog))
}

// AttachGeneric is used to attach the BPF program using autodetection
// for the attach target. You can specify the destination in BPF code
// via the SEC() such as `SEC("fentry/some_kernel_func")`
Expand Down
9 changes: 9 additions & 0 deletions selftest/set-attach/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ func main() {
os.Exit(-1)
}

// Test auto attach
autoAttachOrig := prog.Autoattach()
prog.SetAutoattach(!autoAttachOrig)
if prog.Autoattach() == autoAttachOrig {
fmt.Fprintln(os.Stderr, "set auto attach failed")
os.Exit(-1)
}
prog.SetAutoattach(autoAttachOrig)

err = bpfModule.BPFLoadObject()
if err != nil {
fmt.Fprintln(os.Stderr, err)
Expand Down
Loading