bpf_struct_o...or_each_prog(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… bpf_struct_ops_for_each_prog(9)

okay bestie, welcome to the Kernel API Manual ✨ β€” yes this is a real function name, no I did not make it up, and yes it is lowkey a mouthful. we're doing bpf_struct_ops_for_each_prog today and honestly? it's giving little-helper-that-could 🫢


🌸 NAME 🌸

bpf_struct_ops_for_each_prog β€” invoke @cb for each member prog πŸ’«


✨ SYNOPSIS ✨

int bpf_struct_ops_for_each_prog (const void *kdata , int (*cb)(struct
       bpf_prog *prog, void *data) , void *data );

she's long, she's got a function pointer in the middle, she's iconic. type it carefully bestie πŸ’…


πŸŽ€ ARGUMENTS πŸŽ€

  • kdata β€” the kernel-side struct_ops vmtable. iykyk β€” this is the same kdata arg you hand to ->reg / ->update / ->unreg. your entry pass 🎟️
  • cb β€” the callback, invoked once per member prog. super important: a non-zero return from this bad boy stops the iteration. not me ending the whole loop early 😭
  • data β€” opaque argument, just gets passed straight through to cb. she's a vibe carrier, no questions asked πŸ”₯

πŸ¦‹ DESCRIPTION πŸ¦‹

so what does she do? she walks the struct_ops member progs that are registered on the map containing kdata β€” like a little tour guide for your progs 🧚

this is intended for use from struct_ops ->reg callbacks (and similar) that need to inspect the loaded BPF programs. and fr fr, the classic example: discovering the maps they reference via prog->aux->used_maps πŸ‘‘

Return 0 if iteration completed, otherwise the first non-zero cb return. periodt. πŸ’œ

ngl, remember that early-exit rule β€” the moment your cb returns non-zero, the loop is done, and that value is what comes back out. main character exit energy πŸ’€

🌈 SEE ALSO 🌈

  • Kernel file ./kernel/bpf/bpf_struct_ops.c β€” go read the source bestie, she's right there πŸ“–

and that's the whole page! πŸ’– brought to you by the fine folks over at ./kernel/bpf, dated October 2026 β€” mwah, slay, go write some struct_ops 🫢🌸✨

πŸ“¦ where this page comes from