mirror of
https://github.com/eunomia-bpf/bpf-developer-tutorial.git
synced 2026-02-04 02:34:16 +08:00
layout, title, date, category, author, tags, summary
| layout | title | date | category | author | tags | summary | |||
|---|---|---|---|---|---|---|---|---|---|
| post | tc | 2022-10-10 16:18 | bpftools | yunwei37 |
|
a minimal example of a BPF application use tc |
tc (short for Traffic Control) is an example of handling ingress network traffics.
It creates a qdisc on the lo interface and attaches the tc_ingress BPF program to it.
It reports the metadata of the IP packets that coming into the lo interface.
$ sudo ecli ./package.json
...
Successfully started! Please run `sudo cat /sys/kernel/debug/tracing/trace_pipe` to see output of the BPF program.
......
The tc output in /sys/kernel/debug/tracing/trace_pipe should look
something like this:
$ sudo cat /sys/kernel/debug/tracing/trace_pipe
node-1254811 [007] ..s1 8737831.671074: 0: Got IP packet: tot_len: 79, ttl: 64
sshd-1254728 [006] ..s1 8737831.674334: 0: Got IP packet: tot_len: 79, ttl: 64
sshd-1254728 [006] ..s1 8737831.674349: 0: Got IP packet: tot_len: 72, ttl: 64
node-1254811 [007] ..s1 8737831.674550: 0: Got IP packet: tot_len: 71, ttl: 64
Compile and Run
Compile:
docker run -it -v `pwd`/:/src/ yunwei37/ebpm:latest
or compile with ecc:
$ ecc tc.bpf.c
Compiling bpf object...
Packing ebpf object and config into package.json...
Run:
sudo ecli ./package.json