ebpf-engineering
Use when the user asks about eBPF programs, libbpf, CO-RE, BTF, kprobes, fentry, tracepoints, uprobes, XDP to drop packets, tc BPF, BPF maps, ring buffers…
от j4flmao★ 47 звёзд на GitHub
Установить ebpf-engineering в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Об этом скилле
eBPF Engineering
Purpose
eBPF runs verified, sandboxed programs inside the Linux kernel at kernel events (function entry, tracepoints, packets, syscalls, LSM hooks) without writing a kernel module. This skill covers choosing the hook, writing CO-RE programs that load on many kernels, passing data through maps, satisfying the verifier, and shipping a loader.
Agent Protocol
Trigger
"eBPF", "libbpf", "CO-RE", "BTF", "kprobe", "fentry", "tracepoint", "uprobe", "XDP", "tc BPF", "BPF map", "ring buffer", "verifier", "bpftrace", "cilium/ebpf", "aya".
Input Context
- Goal (tracing/observability, networking, security enforcement)
- Minimum kernel version and distros in the fleet; whether
/sys/kernel/btf/vmlinuxexists - Loader language (C/libbpf, Go/cilium-ebpf, Rust/aya or libbpf-rs)
Output Artifact
BPF C program, loader code, build commands, verifier-error diagnosis. No file unless requested.
Response Format
Min kernel: {version} (BTF: yes/no)
Hook: {program type + attach point}
Maps: {name | type | key -> value | max_entries}
BPF code: {snippet}
Loader: {snippet / skeleton usage}
Verifier notes: {bounds checks, loops, stack}
1. Model
- Restricted C compiled by Clang to BPF bytecode (
clang -O2 -g -target bpf), loaded withbpf(); the verifier proves safety (bounded execution, valid memory access, no uninitialised reads, correct helper usage); the JIT compiles to native code. - Programs are event driven; state lives in maps shared with user space. Programs need
CAP_BPF(+CAP_PERFMON/CAP_NET_ADMINdepending on type) since 5.8, or root.
2. Choosing the Hook
| Need | Program type | Notes |
|---|---|---|
| Trace a kernel function | fentry/fexit (BPF trampoline, ≥ 5.5) |
faster than kprobes, typed args via BTF |
| Trace any kernel function on older kernels | kprobe/kretprobe |
unstable: functions get inlined/renamed |
| Stable kernel events | tracepoints / tp_btf raw tracepoints |
prefer over kprobes when one exists |
| User-space functions | uprobe/uretprobe, USDT |
e.g. TLS library calls; per-process overhead on each hit |
| Packet processing at the driver | XDP | earliest hook; XDP_DROP/PASS/TX/REDIRECT; see references/xdp-networking.md |
| Packet processing with skb metadata | tc (BPF_PROG_TYPE_SCHED_CLS, tcx links ≥ 6.6) |
ingress + egress |
| Security policy | BPF LSM (lsm/ hooks, ≥ 5.7, lsm=...,bpf boot param) |
can deny operations |
| Per-cgroup socket/network control | cgroup programs | connect, bind, sockops |
3. CO-RE Program Example
// execsnoop.bpf.c — log process execs via a stable tracepoint
#include "vmlinux.h" // bpftool btf dump file /sys/kernel/btf/vmlinux format c
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_core_read.h>
struct event { u32 pid; u32 ppid; char comm[16]; };
struct {
__uint(type, BPF_MAP_TYPE_RINGBUF);
__uint(max_entries, 256 * 1024); // bytes, power of two, multiple of page size
} events SEC(".maps");
SEC("tp/sched/sched_process_exec")
int handle_exec(struct trace_event_raw_sched_process_exec *ctx)
{
struct event *e = bpf_ringbuf_reserve(&events, sizeof(*e), 0);
if (!e)
return 0; // buffer full: drop, count it in a map
struct task_struct *task = (struct task_struct *)bpf_get_current_task();
e->pid = bpf_get_current_pid_tgid() >> 32;
e->ppid = BPF_CORE_READ(task, real_parent, tgid); // CO-RE relocated field access
bpf_get_current_comm(e->comm, sizeof(e->comm));
bpf_ringbuf_submit(e, 0);
return 0;
}
char LICENSE[] SEC("license") = "GPL";
Build and load with a skeleton:
clang -O2 -g -target bpf -D__TARGET_ARCH_x86 -c execsnoop.bpf.c -o execsnoop.bpf.o
bpftool gen skeleton execsnoop.bpf.o > execsnoop.skel.h
struct execsnoop_bpf *skel = execsnoop_bpf__open_and_load();
if (!skel) { fprintf(stderr, "load failed: %s\n", strerror(errno)); return 1; }
if (execsnoop_bpf__attach(skel)) { /* handle error */ }
struct ring_buffer *rb = ring_buffer__new(bpf_map__fd(skel->maps.events), on_event, NULL, NULL);
while (!stop) ring_buffer__poll(rb, 100 /* ms */);
- CO-RE:
BPF_CORE_READ,bpf_core_field_exists(), and___suffixstruct flavours let one object run across kernel versions; the loader relocates field offsets using the running kernel's BTF. Kernels without BTF need BTFHub-style external BTF files. - Go:
cilium/ebpfwithbpf2go; Rust:aya(BPF side in Rust too) orlibbpf-rsskeletons.
4. Maps
| Type | Use |
|---|---|
HASH / LRU_HASH |
per-key state (per-PID, per-flow); LRU evicts under pressure |
ARRAY / PERCPU_ARRAY |
counters, config, scratch buffers (per-CPU avoids atomics and the 512-byte stack limit) |
PERCPU_HASH |
high-rate counters without contention |
RINGBUF (≥ 5.8) |
events to user space, ordered across CPUs, shared buffer — prefer over PERF_EVENT_ARRAY |
LPM_TRIE |
IP prefix matching |
| `PROG_A |
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
- references/xdp-networking.md
FAQ
Что делает скилл ebpf-engineering?
Use when the user asks about eBPF programs, libbpf, CO-RE, BTF, kprobes, fentry, tracepoints, uprobes, XDP to drop packets, tc BPF, BPF maps, ring buffers, verifier errors, bpftrace, cilium/ebpf or aya. Produces loadable eBPF programs and loaders. Not for Cilium cluster setup (use cilium-ebpf) or detection rules (use ebpf-threat-detection).
Как установить скилл ebpf-engineering?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл ebpf-engineering запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
AnthropicToolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
access
AnthropicManage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
configure
AnthropicSet up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
access
AnthropicManage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…