bpftool-link(8)
β¨ bpftool-link β the manual, but make it cute β¨
okay bestie, gather round, because this is bpftool-link(8) β straight out of the System Manager's Manual, section 8. It's the tool for inspection and simple manipulation of eBPF links. Yes, links. The little handles that keep your BPF program glued to its hook. Let's get into it π
πΈ NAME πΈ
bpftool-link β tool for inspection and simple manipulation of eBPF links π¦
β¨ SYNOPSIS β¨
bpftool [OPTIONS] link COMMAND
OPTIONS := { { -j | --json } [{ -p | --pretty }] | { -d | --debug } | {
-f | --bpffs } | { -n | --nomount } }
COMMANDS := { show | list | pin | help }
π LINK COMMANDS π
Here's the whole menu, no gatekeeping:
bpftool link { show | list } [LINK]
bpftool link pin LINK FILE
bpftool link detach LINK
bpftool link help
LINK := { id LINK_ID | pinned FILE }
π DESCRIPTION π
bpftool link { show | list } [LINK]
Show info about all your active links, bestie. If you pass LINK, it shows info about only that one link β otherwise it lists every link currently active on the system. Main character energy, one link at a time or the whole squad π
The output starts with the link ID, then the link type, then zero or more named attributes β and some of those attributes depend on the type of link. Like, obviously.
Since Linux 5.8, bpftool is able to discover information about processes that hold open file descriptors (FDs) against BPF links. On kernels like that, bpftool will automatically emit this information too. It's giving β¨thoroughβ¨.
bpftool link pin LINK FILE
Pin link LINK as FILE. Locking it down, keeping it safe π
β οΈ Note, and this matters:FILEmust be located in abpffsmount. It must not contain a dot character ('.'), because that's reserved for future extensions ofbpffs. No dots. Periodt. π
bpftool link detach LINK
Force-detach link LINK. And listen: the BPF link and its underlying BPF program will stay valid, but they will be detached from the respective BPF hook, and the BPF link will transition into a defunct state until the last open file descriptor for that link is closed. So it's not dead, it's just... unmoored. Floating. π
bpftool link help
Print a short help message. That's it, that's the whole thing π«Ά
π OPTIONS π
-h,--helpβ Print short help message (similar tobpftool help). Your little safety net π§-V,--versionβ Printbpftool's version number (similar tobpftool version), the number of thelibbpfversion in use, and optional features that were included whenbpftoolwas compiled. Those optional features include linking against LLVM or libbfd to provide the disassembler for JIT-ted programs (bpftool prog dump jited), and usage of BPF skeletons (some features likebpftool prog profile, or showing pids associated to BPF objects, may rely on it). Receipts on demand π§Ύ-j,--jsonβ Generate JSON output. For commands that can't produce JSON, this option has no effect. No effect! It simply does nothing there, bestie π-p,--prettyβ Generate human-readable JSON output. Implies-j. So it's basically-jbut dressed up π-d,--debugβ Print all logs available, even debug-level information. This includes logs fromlibbpfas well as from the verifier, when attempting to load programs. Spill the tea, verifier β-f,--bpffsβ When showing BPF links, show file names of pinned links. Show-off behaviour, love that for us π-n,--nomountβ Do not automatically attempt to mount any virtual file system (such astracefsor BPF virtual file system) when necessary. Hands off the mounting, thanks π ββοΈ
π EXAMPLES π
okay these are the receipts, copy them exactly:
the classic vibe check
# bpftool link show
10: cgroup prog 25
cgroup_id 614 attach_type egress
pids test_progs(223)
same energy, but make it JSON
# bpftool --json --pretty link show
[{
"type": "cgroup",
"prog_id": 25,
"cgroup_id": 614,
"attach_type": "egress",
"pids": [{
"pid": 223,
"comm": "test_progs"
}
]
}
]
pinning, then peeking at the result
# bpftool link pin id 10 /sys/fs/bpf/link
# ls -l /sys/fs/bpf/
-rw------- 1 root root 0 Apr 23 21:39 link
Look at that. Pinned. Iconic π₯
π¦ SEE ALSO π¦
bpf(2), bpf-helpers(7), bpftool(8), bpftool-btf(8), bpftool-cgroup(8), bpftool-feature(8), bpftool-gen(8), bpftool-iter(8), bpftool-map(8), bpftool-net(8), bpftool-perf(8), bpftool-prog(8), bpftool-struct_ops(8), bpftool-token(8)
The whole friend group, fr fr π go read them all, they're all slaying in section 8.
and that's the page bestie! π this one lives in the System Manager's Manual as bpftool-link(8) β go forth, inspect your links, pin responsibly, and remember: no dots in the bpffs filename. mwah π
πβ¨
π¦ where this page comes from
- arch rolling: bpf 7.3.1-1 Β· GPL-2.0-only
- ubuntu stonking: bpftool 7.8.0+7.3.0-10.10
- ubuntu stonking: bpftool 7.8.0+7.3.0-9.9
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms