Thursday, September 16, 2021

BCC programming 筆記

安裝 BCC 使用 Source Code
For Bionic (18.04 LTS)

Install related libraries and packages
$ sudo apt-get -y install bison build-essential cmake flex git libedit-dev \
libllvm6.0 llvm-6.0-dev libclang-6.0-dev python zlib1g-dev libelf-dev \
iperf3 luajit libluajit-5.1-dev netperf linux-headers-$(uname -r)

Compile BCC source code and install
$ git clone --recursive https://github.com/iovisor/bcc.git
$ git submodule update --recursive
# Or $ git pull --recurse-submodules

$ mkdir bcc/build; cd bcc/build
$ cmake .. -DCMAKE_INSTALL_PREFIX=/usr -DPYTHON_CMD="python python3.8"
$ make -j `nproc`
$ sudo make install 


Quick Start Guide

A Docker container is provided for user to try out bcc.

From your host shell:

docker run -it --rm \
  --privileged \
  -v /lib/modules:/lib/modules:ro \
  -v /usr/src:/usr/src:ro \
  -v /etc/localtime:/etc/localtime:ro \
  --workdir /usr/share/bcc/tools \
  zlim/bcc

Linux Kernel Source Code查詢


Using eBPF in Kubernetes

How can I determine which namespaces a PID is in from kernel space?
P.S:
container id can be found in
cat /proc/self/cgroup | grep -o -e "docker-.*.scope" | head -n 1 | sed "s/docker-\(.*\).scope/\\1/"

How can I retrieve a task's session_id in an eBPF program?
P.S:
Linux PID, PPID, PGID (Process Group Leader), SID (Session Leader)
PGID — Process Group Identifier (Process Group Leader)
ps -Ao pid,ppid,command

SID — Session Identifier (Session Leader)


Tracee - Container and system tracing using eBPF

eBPFlow
This project aims to offer a packet flow tracer based on eBPF
Paper:

Source Code:


BPF 筆記 ( 安裝與BCC Python)


BCC 很好的範例, 利用BPF從Layer2 到 Layer4 擷取packet相關資訊




Persistent eBPF map object with bcc (可保存Map's data in the file descriptor)
簡單範例 BPF Map の永続化

eBPF Maps Introduction

[文章]Cloudflare architecture and how BPF eats the world

No comments: