From b7bd38ebb52188de2575d46b3e0ccca31a64de2c Mon Sep 17 00:00:00 2001 From: Tao Chen Date: Mon, 8 Apr 2024 11:31:21 +0800 Subject: [PATCH] chore(selftest): Add tc Query test case The bpf_tc_query interface should init the parameter first, sometimes it may be confused for us, so add the test case to reduce the confusion. https://github.com/aquasecurity/libbpfgo/issues/421 Signed-off-by: Tao Chen --- selftest/tc/main.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/selftest/tc/main.go b/selftest/tc/main.go index 0174eb16..6a8f1d7d 100644 --- a/selftest/tc/main.go +++ b/selftest/tc/main.go @@ -56,12 +56,27 @@ func main() { var tcOpts bpf.TcOpts tcOpts.ProgFd = int(tcProg.GetFd()) + tcOpts.Flags = bpf.BpfTcFReplace + tcOpts.Handle = 1 err = hook.Attach(&tcOpts) if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(-1) } + tcOpts.Flags = 0 + tcOpts.ProgFd = 0 + tcOpts.ProgId = 0 + err = hook.Query(&tcOpts) + if err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(-1) + } + if tcOpts.Handle != 1 { + fmt.Fprintln(os.Stderr, "query info error, handle:%d", tcOpts.Handle) + os.Exit(-1) + } + eventsChannel := make(chan []byte) rb, err := bpfModule.InitRingBuf("events", eventsChannel) if err != nil {