Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kubearmor/libbpf
KubeArmor eBPF Go library based on Linux libbpf API
https://github.com/kubearmor/libbpf
bpf ebpf go golang kubearmor
Last synced: 3 months ago
JSON representation
KubeArmor eBPF Go library based on Linux libbpf API
- Host: GitHub
- URL: https://github.com/kubearmor/libbpf
- Owner: kubearmor
- License: apache-2.0
- Created: 2021-07-26T11:30:52.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-12-15T14:55:00.000Z (about 1 year ago)
- Last Synced: 2024-10-01T14:26:43.301Z (3 months ago)
- Topics: bpf, ebpf, go, golang, kubearmor
- Language: Go
- Homepage:
- Size: 68.4 KB
- Stars: 4
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# libbpf
## KubeArmor bpf library
One will only be able to `go get` and to use this go module (library) setting the `CGO_LDFLAGS` environment variable, since this is based on the aqua security [libbpfgo](https://github.com/aquasecurity/libbpfgo) that is a `cgo` wrapper of the C [libbpf](https://github.com/libbpf/libbpf).
*So be aware that using this library in your go code turns it into cgo code.*
---
## General Dependencies
### Ubuntu
`linux-tools-generic`
`libelf-dev`
`zlib1g-dev`
`clang`
---
## Using this library
One way is to use the shared library `libbpf.so` if it is already installed.
`❯ CGO_LDFLAGS="/usr/lib/libbpf.so" go get github.com/kubearmor/libbpf`
However, currently, the most common is to use the `libbpf.a` (static version). To do so, follow the steps below.
- Clone this repository.
`❯ git clone github.com/kubearmor/libbpf`
- Inside the repository folder, run make to download the C libbpf code and compile it.
`❯ make`
This will generate the static `libbpf.a` file and the `vmlinux.h` and `bpf/*.h` headers inside `./include`.
- Now one is able to make correct use of this library. Be sure to use absolute paths.
`❯ CGO_LDFLAGS="/path_to_this_repo/include/libbpf.a" CGO_CFLAGS="-I /path_to_this_repo/include" go get github.com/kubearmor/libbpf`
The same environment variable need to be set when building the final application that uses this library.
`❯ CGO_LDFLAGS="/path_to_this_repo/include/libbpf.a" CGO_CFLAGS="-I /path_to_this_repo/include" go build`
### Testing it
The use cases inside [tests](tests/) can be tested using make.
`❯ make run-tests`
---
### KABPFMapElement interface
To satisfy `KABPFMapElement` interface, it's necessary to implement the following methods for an XXMapElem.
```go
func (pme *XXMapElem) KeyPointer() unsafe.Pointer {
...
}func (pme *XXMapElem) ValuePointer() unsafe.Pointer {
...
}func (pme *XXMapElem) SetFoundValue(value []byte) {
...
}func (pme *XXMapElem) MapName() string {
return "map_name"
}
```Examples can also be found in [tests](tests/).