Basic eBPF examples in Golang using libbpfgo

Overview

libbpfgo-beginners

Basic eBPF examples in Golang using libbpfgo.

Install Go

See the Go documentation

Install packages

sudo apt-get update
sudo apt-get install libbpf-dev make clang llvm libelf-dev

Building and running hello

make all
sudo ./hello

This builds two things:

  • dist/hello.bpf.o - an object file for the eBPF program
  • hello - a Go executable

The Go executable reads in the object file at runtime. Take a look at the .o file with readelf if you want to see the sections defined in it.

Notes

I'm using Ubuntu 20.10, kernel 5.8, go 1.15

This approach installs the libbpf-dev package. Another alternative (which is what Tracee does) is to install the libbpf source as a git submodule, and build it from source.

You might also like...
Minimal Linux Live (MLL) is a tiny educational Linux distribution, which is designed to be built from scratch by using a collection of automated shell scripts. Minimal Linux Live offers a core environment with just the Linux kernel, GNU C library, and Busybox userland utilities.
Minimal Linux Live (MLL) is a tiny educational Linux distribution, which is designed to be built from scratch by using a collection of automated shell scripts. Minimal Linux Live offers a core environment with just the Linux kernel, GNU C library, and Busybox userland utilities.

Minimal Linux Live (MLL) is a tiny educational Linux distribution, which is designed to be built from scratch by using a collection of automated shell scripts. Minimal Linux Live offers a core environment with just the Linux kernel, GNU C library, and Busybox userland utilities.

Applied SDLC using C language
Applied SDLC using C language

SDLC Activity Based Learning Build Code Quality Unity Git Inspector Folder Structure Folder Description 1_Requirements Documents detailing requirement

A demonstration of implementing, and using, a "type safe", extensible, and lazy iterator interface in pure C99.

c-iterators A demonstration of implementing, and using, a "type safe", extensible, and lazy iterator interface in pure C99. The iterable is generic on

Problem solving on HackerRank platform using C++.

Efficient solutions to HackerRank CPP problems! ℹ️ Introduction : Subdomaine Title Points Source Intro Say "Hello, World!" With C++ 5 Solution Intro I

Teach the C programming language using a collection of super beginner friendly tutorials and challenges.
Teach the C programming language using a collection of super beginner friendly tutorials and challenges.

TeachMeCLikeIm5 You are welcome to contribute to this repo. See the CONTRIBUTING.md for more info 📜 About this repo 📜 A collection of super beginner

Implementation using C in programming lab class when being Teacher Assistant.

C Programming Lab Implementation using C in programming lab class when being Teacher Assistant. The problems are here Problems and Description Week2 w

3D software rasterizer using C/ C++

REX Rex is a side project I'm working on now for the purpose of learning more about graphics programming and rendering. Currently it's just a 3D softw

A very basic eBPF Load Balancer in a few lines of C

An eBPF Load Balancer from scratch As seen at eBPF Summit 2021. This is not production ready :-) This uses libbpf as a git submodule. If you clone thi

Sample module for FreeSWITCH using golang

freeswitch_module_golang_sample Sample module for FreeSWITCH using golang tl; dr

Example program using eBPF to log data being based in using shell pipes

Example program using eBPF to log data being based in using shell pipes (|)

A basic C++ cryptocurrency/block-chain. Includes a basic wallet system. See README.md for all the inclusions and future additions.

Cryptocurrency Project C++ cryptocurrency/block-chain. Mostly basic blockchain for now. New Additions are in the works(see below). This file details w

A golang-style C++ coroutine library and more.

CO is an elegant and efficient C++ base library that supports Linux, Windows and Mac platforms. It pursues minimalism and efficiency, and does not rely on third-party library such as boost.

Stage 1 C2 Written in Golang

Hitman Stage 1 tool for persistence on a target environment. All implants are meant to be extemely limited with the sole purpose of persisting on a ta

Port of Golang channels to C++

Copper is a C++ library of a powerful queue object for communication between threads. It is based on Go's channels and follows the quote: Don't commun

Free,Open-Source,Cross-platform agent and Post-exploiton tool written in Golang and C++, the architecture and usage like Cobalt Strike
Free,Open-Source,Cross-platform agent and Post-exploiton tool written in Golang and C++, the architecture and usage like Cobalt Strike

Khepri Free,Open-Source,Cross-platform agent and Post-exploiton tool written in Golang and C++ Description Khepri is a Cross-platform agent, the archi

A tiny cross-platform webview library for C/C++/Golang to build modern cross-platform GUIs.

webview for golang and c/c++ A tiny cross-platform webview library for C/C++/Golang to build modern cross-platform GUIs. The goal of the project is to

Standalone MinHook wrapper for Golang.

Standalone version of GoMinHook! Credit to https://github.com/NaniteFactory/gominhook and https://github.com/TsudaKageyu/minhook as almost all of the

Golang template grammar for tree-sitter

tree-sitter-go-template Golang templates grammar for tree-sitter. NeoVim integration using nvim-treesitter Add gotmpl parser following nvim-treesitter

Golang bindings for Nvidia Datacenter GPU Manager (DCGM)

Bindings Golang bindings are provided for NVIDIA Data Center GPU Manager (DCGM). DCGM is a set of tools for managing and monitoring NVIDIA GPUs in clu

Comments
  • feat: add Dockerfile to easily compile program

    feat: add Dockerfile to easily compile program

    Hi @lizrice, I really appreciate your work. I hope this PR could be useful for your project in order to avoid compatibility issues with the environment.

    opened by alegrey91 1
  • Compilation errors on Ubuntu_20

    Compilation errors on Ubuntu_20

    :~/ebpf/lizrice/libbpfgo-beginners$ make CC=clang CGO_CFLAGS="-I /usr/include/bpf" CGO_LDFLAGS="/usr/lib/x86_64-linux-gnu/libbpf.a" go build -o hello

    runtime/cgo

    clang: error: no such file or directory: '/usr/lib/x86_64-linux-gnu/libbpf.a' make: *** [Makefile:17: hello] Error 2 :~/ebpf/lizrice/libbpfgo-beginners$ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 20.04 LTS Release: 20.04 Codename: focal :~/ebpf/lizrice/libbpfgo-beginners$

    opened by prasadnallani 1
Owner
Liz Rice
VP Open Source Engineering at @aquasecurity | @cncf Technical Oversight Committee chair | O'Reilly Container Security author
Liz Rice
This the contains the test examples and validator tool for the ISPD2021 Wafer-Scale Physics Modeling contest.

This readme documents information regarding the validator/scorer which will be used for the 2021 ISPD Contest problem: Wafer-Scale Physics Modelling

Cerebras 16 Aug 22, 2022
Small beginners C program examples.

Small beginner C programs.

null 23 Feb 18, 2022
This repository is a summary of the basic knowledge of recruiting job seekers and beginners in the direction of C/C++ technology, including language, program library, data structure, algorithm, system, network, link loading library, interview experience, recruitment, recommendation, etc.

?? C/C++ 技术面试基础知识总结,包括语言、程序库、数据结构、算法、系统、网络、链接装载库等知识及面试经验、招聘、内推等信息。This repository is a summary of the basic knowledge of recruiting job seekers and beginners in the direction of C/C++ technology, including language, program library, data structure, algorithm, system, network, link loading library, interview experience, recruitment, recommendation, etc.

huihut 25.8k Sep 16, 2022
Basic Fortnite Internal Cheat Source

Basic Fortnite Internal Cheat Source That's a basic fortnite cheat internal source for pasters and for people that just want to learn from it. This is a trash code that will be improved when I have time and when I want.

Android1337 13 Jun 13, 2022
PL/0 to C compiler to teach basic compiler construction from a practical, hands-on perspective.

pl0c pl0c is a compiler for the PL/0 language. It reads in PL/0 source code and outputs equivalent C source code. It was written to be the subject of

Brian Callahan 94 Aug 25, 2022
C++ Programs from Basic to Advanced lavel.

✨️ C++ Programs (Basic to Advanced Level) ??️ ??️ Local Environment Setup If you are still willing to set up your environment for C++, you need to hav

Atul Tripathi 1 Oct 23, 2021
✨️ C Programs (Basic to Advanced Level - Chapter wise) 🚀️

✨️ C Programs (Basic to Advanced Level - Chapter wise) ??️ ??️ Tutorial Table Days Topics Day 1 Chapter 1: Variables, Constants, and Keywords Day 2 Ch

Atul Tripathi 1 Oct 22, 2021
Learn basic elements in C++ and learn CMake

learn-cpp-cmake Learn basic elements in C++ and learn CMake This repo has code from several sources. If you think we have violated any copyright law o

mafiaboy009 6 Mar 1, 2022
A BASIC Compiler and IDE for Amiga Computers

AQB: A BASIC Compiler and IDE for Amiga Computers About Project Scope Requirements Installation Benchmark Results Source Code Command Reference Refere

Guenter Bartsch 57 Sep 19, 2022
A project uses for beginners, who wants to learn basic Cpp.

Learning Basic Cpp The basic project for who wants to learn Cpp. Notes: All the files are coded using Microsoft Visual Studio 2019. If you want to cod

null 1 Jan 28, 2022