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

[Error] in running go user space code #383

Open
VedRatan opened this issue Oct 9, 2023 · 1 comment
Open

[Error] in running go user space code #383

VedRatan opened this issue Oct 9, 2023 · 1 comment

Comments

@VedRatan
Copy link

VedRatan commented Oct 9, 2023

On trying to run my go user space code the following error logs are generated:

CGO_ENABLED=1 go run drop.go
# github.com/aquasecurity/libbpfgo
../go/pkg/mod/github.com/aquasecurity/[email protected]/libbpfgo.go:30:9: could not determine kind of name for C.LIBBPF_MAJOR_VERSION
../go/pkg/mod/github.com/aquasecurity/[email protected]/libbpfgo.go:35:9: could not determine kind of name for C.LIBBPF_MINOR_VERSION
../go/pkg/mod/github.com/aquasecurity/[email protected]/libbpfgo.go:188:55: could not determine kind of name for C.LIBBPF_STRICT_AUTO_RLIMIT_MEMLOCK
../go/pkg/mod/github.com/aquasecurity/[email protected]/libbpfgo.go:189:55: could not determine kind of name for C.LIBBPF_STRICT_MAP_DEFINITIONS
../go/pkg/mod/github.com/aquasecurity/[email protected]/libbpfgo.go:187:55: could not determine kind of name for C.LIBBPF_STRICT_NO_OBJECT_LIST
../go/pkg/mod/github.com/aquasecurity/[email protected]/libbpfgo.go:186:55: could not determine kind of name for C.LIBBPF_STRICT_SEC_NAME
../go/pkg/mod/github.com/aquasecurity/[email protected]/libbpfgo.go:477:7: could not determine kind of name for C.bpf_object__next_map
../go/pkg/mod/github.com/aquasecurity/[email protected]/libbpfgo.go:517:7: could not determine kind of name for C.bpf_object__next_program
../go/pkg/mod/github.com/aquasecurity/[email protected]/libbpfgo.go:770:21: could not determine kind of name for C.bpf_program__type
../go/pkg/mod/github.com/aquasecurity/[email protected]/libbpfgo.go:1565:16: could not determine kind of name for C.libbpf_probe_bpf_map_type
../go/pkg/mod/github.com/aquasecurity/[email protected]/libbpfgo.go:1573:16: could not determine kind of name for C.libbpf_probe_bpf_prog_type

my go.mod file configurations:

module github.com/VedRatan/ebpf

go 1.21.2

require github.com/aquasecurity/libbpfgo v0.5.1-libbpf-1.2

my go file:

package main

import (
	"C"
	"fmt"

	bpf "github.com/aquasecurity/libbpfgo"
)

import (
	"os"
	"os/signal"
	"syscall"
)

func main() {
	sig := make(chan os.Signal, 1)
	signal.Notify(sig, os.Interrupt)

	b, err := bpf.NewModuleFromFile("dropipv4.o")
	if err != nil {
		panic(err)
	}
	defer b.Close()

	err = b.BPFLoadObject()
	if err != nil {
		panic(err)
	}

	prog, err := b.GetProgram("capture_packets")
	if err != nil {
		panic(err)
	}

	// Specify the network interface name to attach the XDP program to
	ifaceName := "wlo1" // Replace with your network interface name

	link, err := prog.AttachXDP(ifaceName)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error attaching XDP program: %v\n", err)
		os.Exit(1)
	}

	fmt.Printf("XDP program attached to wlo1\n")

	// mapName := "rxcnt"

	// mp, err := b.GetMap(mapName)
	// if err != nil {
	// 	fmt.Fprintf(os.Stderr, "Error getting map: %v\n", err)
	// 	os.Exit(1)
	// }

	// Wait for a signal to keep the program running
	sig = make(chan os.Signal, 1)
	signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM)
	<-sig

	// Detach the XDP program when the program exits
	if err := link.Destroy(); err != nil {
		fmt.Fprintf(os.Stderr, "Error detaching XDP program: %v\n", err)
	}
}


@geyslan
Copy link
Member

geyslan commented Oct 9, 2023

Hello @VedRatan. I would suggest you to compose your build based on https://github.com/aquasecurity/libbpfgo/tree/main/selftest/common and your use of the libbpfgo (user/bpf) based on some selftest https://github.com/aquasecurity/libbpfgo/tree/main/selftest/map-update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants