diff --git a/prog.go b/prog.go index 3a0bf5d0..2feddbdb 100644 --- a/prog.go +++ b/prog.go @@ -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")` diff --git a/selftest/set-attach/main.go b/selftest/set-attach/main.go index a56fc30b..c29faa86 100644 --- a/selftest/set-attach/main.go +++ b/selftest/set-attach/main.go @@ -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)