GithubHelp home page GithubHelp logo

isabella232 / gobpf Goto Github PK

View Code? Open in Web Editor NEW

This project forked from datadog/gobpf

0.0 0.0 0.0 419 KB

Go bindings for creating BPF programs.

License: Apache License 2.0

Go 72.33% C 26.44% Shell 1.23%

gobpf's Introduction

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 at an early stage but is usable nonetheless. Input and contributions are very welcome.

We recommend vendoring gobpf and pinning its version as the API is likely to 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 the latest released version of libbcc (either using a package manager or by building from source).

github.com/iovisor/gobpf/elf

Building ELF Object Files

To build ELF object files for use with the elf package, you must use specific sections (SEC("...")). The following are currently supported:

  • kprobe/...
  • cgroup/skb
  • cgroup/sock
  • maps/...
  • socket...
  • tracepoint...
  • uprobe/...
  • uretprobe/...
  • xdp/...

Map definitions must correspond to bpf_map_def from the elf package. Otherwise, you will encounter an error like only one map with size 280 bytes allowed per section (check bpf_map_def).

The Cilium BPF docs contain helpful info for using clang/LLVM to compile programs into elf object files: https://cilium.readthedocs.io/en/latest/bpf/#llvm

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

Examples

Sample code can be found in the examples/ directory. Examples can be run as follows:

sudo -E go run examples/bcc/perf/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 ./...

gobpf's People

Contributors

schu avatar iaguis avatar alban avatar shang-wang avatar tuxology avatar gui774ume avatar bobrik avatar safchain avatar tklauser avatar rabbitstack avatar sfluor avatar calavera avatar drzaeus77 avatar l3n41c avatar p-lambert avatar pryz avatar higebu avatar lebauce avatar gustavokatel avatar dmitrivereshchagin avatar brycekahle avatar bhiggins avatar wofanli avatar chenlingpeng avatar photoszzt avatar stantheman avatar sangyun-han avatar mkfsn avatar nplanel avatar nathanfrench avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.