From 3a256f4d5794c442e5afc5203e31c15a26539962 Mon Sep 17 00:00:00 2001 From: Tao Chen Date: Sun, 10 Mar 2024 00:57:56 +0800 Subject: [PATCH] chore(prog): Add autoattach api Signed-off-by: Tao Chen --- prog.go | 8 ++++++++ selftest/set-attach/main.go | 6 ++++++ 2 files changed, 14 insertions(+) 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..d5693f6e 100644 --- a/selftest/set-attach/main.go +++ b/selftest/set-attach/main.go @@ -40,6 +40,12 @@ func main() { os.Exit(-1) } + prog.SetAutoattach(false) + if prog.Autoattach() { + fmt.Println(os.Stderr, "set auto attach failed") + os.Exit(-1) + } + err = bpfModule.BPFLoadObject() if err != nil { fmt.Fprintln(os.Stderr, err)