bpftool-iter(8)
β¨ NAME β¨
okay so bestie, this is bpftool-iter β the little corner of bpftool(8) (that's its home manual, section 8, System Manager's Manual, iykyk) that's literally just about making BPF iterators. That's the whole job. Slay.
πΈ SYNOPSIS πΈ
the vibe check on how you actually call it:
bpftool [OPTIONS] iter COMMAND
OPTIONS := { { -j | --json } [{ -p | --pretty }] | { -d | --debug } }
COMMANDS := { pin | help }
π¦ ITER COMMANDS π¦
these are the moves you can pull π
bpftool iter pin OBJ PATH [map MAP]
bpftool iter help
OBJ := /a/file/of/bpf_iter_target.o
MAP := { id MAP_ID | pinned FILE }
π DESCRIPTION π
bpftool iter pin OBJ PATH [map MAP]
so a bpf iterator is lowkey a collab π― β it pairs up a kernel iterating over some specific kernel data (think tasks, bpf_maps, etc.) with a bpf program that gets called for each one of those kernel data objects (like one task, one bpf_map, etc.). and then user space can just read the kernel iterator output through the read() syscall. no cap, that's the whole tea.
the pin command creates a bpf iterator from OBJ, and pins it to PATH. and PATH has got to live inside a bpffs mount, periodt. also it must not contain a dot character (.), because that's reserved for future extensions of bpffs. so don't. π
map element bpf iterators need one extra thing: the MAP parameter, so the bpf program can iterate over map elements for that map. that way you can have a bpf program in the kernel running with each map element and doing checking, filtering, aggregation, etc. β without copying data to user space. iconic behavior tbh.
and then, bestie, you just cat PATH to see the bpf iterator output. that's it. that's the moment. β¨
bpftool iter help
prints a short help message. short. sweet. π
π OPTIONS π
-h,--helpβ print a short help message (basically the same energy asbpftool help).-V,--versionβ printbpftool's version number (similar tobpftool version), plus the number of the libbpf version in use, plus any optional features that were compiled into yourbpftool. and what are those optional features, you ask? π things like linking against LLVM or libbfd to give you 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 that).-j,--jsonβ generate JSON output. for commands that can't produce JSON, this option just does nothing. no harm, no foul. π-p,--prettyβ generate human-readable JSON output. and it implies-j, so you don't gotta say both.-d,--debugβ print all the logs available, even debug-level info. that includes logs from libbpf and from the verifier, whenever it's attempting to load programs. maximum yapping mode, we love it π
π EXAMPLES π
watch and learn, bestie:
# bpftool iter pin bpf_iter_netlink.o /sys/fs/bpf/my_netlink
create a file-based bpf iterator out of bpf_iter_netlink.o and pin it to /sys/fs/bpf/my_netlink. π«Ά
# bpftool iter pin bpf_iter_hashmap.o /sys/fs/bpf/my_hashmap map id 20
create a file-based bpf iterator out of bpf_iter_hashmap.o plus the map with id 20, and pin it to /sys/fs/bpf/my_hashmap. ate, no crumbs π
β SEE ALSO β
go read these too, they're all part of the friend group:
bpf(2), bpf-helpers(7), bpftool(8), bpftool-btf(8), bpftool-cgroup(8), bpftool-feature(8), bpftool-gen(8), bpftool-link(8), bpftool-map(8), bpftool-net(8), bpftool-perf(8), bpftool-prog(8), bpftool-struct_ops(8), bpftool-token(8)
and that's the whole page, babes π this was the bpftool-iter(8) manual page straight out of the System Manager's Manual β same section 8, same source, same everything, just with way better vibes. mwah, go pin something ππ¦β¨
π¦ 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