Skip to content

fcrisciani/gobpf

 
 

Repository files navigation

gobpf

Build Status GoDoc

This repository provides go bindings for the bcc framework as well as low-level routines to load and use eBPF programs from .elf files.

gobpf is in early stage, but usable. Input and contributions are very much welcome.

We recommend to vendor gobpf and pin its version as the API probably undergoes change during development.

Requirements

eBPF requires a recent Linux kernel. A good feature list can be found here: https://github.com/iovisor/bcc/blob/master/docs/kernel-versions.md

github.com/iovisor/gobpf/bcc

Install libbcc (either by package or source).

github.com/iovisor/gobpf/elf

Building ELF object files

To build ELF object files for usage with the elf package, you must use distinct sections (SEC("...")). Currently, kprobe/..., cgroup/skb, cgroup/sock and maps/... are supported.

See tests/dummy.c for a minimal dummy and https://github.com/weaveworks/tcptracer-bpf for a real world example.

Examples

Example code can be found in the examples/ directory, e.g.

sudo -E go run examples/perf.go

Tests

The semaphore.sh script can be used to run the tests in rkt stage1-kvm containers on different kernel versions. To run all tests on the host system, use go test as follows:

go test -tags integration -v \
  github.com/iovisor/gobpf \
  github.com/iovisor/gobpf/elf \
  github.com/iovisor/gobpf/bcc

About

Go bindings for creating BPF programs.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 74.3%
  • C 23.2%
  • Shell 2.5%