Skip to content

Commit

Permalink
chore(prog): Add autoattach api
Browse files Browse the repository at this point in the history
Signed-off-by: Tao Chen <chen.dylane@gmail.com>
Co-authored-by: Geyslan Gregório <geyslan@gmail.com>
  • Loading branch information
chentao-kernel and geyslan committed Mar 14, 2024
1 parent 0080df4 commit 6d28299
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
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

0 comments on commit 6d28299

Please sign in to comment.