bpf_convert_filter(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… bpf_convert_filter β€” a Kernel API Manual moment ✨

okay so bestie, welcome to bpf_convert_filter, brought to you by the Kernel API Manual. this one's a converter, and it's giving "glow-up technician for filter programs." let's get into it 🫢


✨ NAME ✨

bpf_convert_filter β€” convert filter program. literally that's the whole job. iconic.


πŸ¦‹ SYNOPSIS πŸ¦‹

int bpf_convert_filter (struct sock_filter *prog , int len , struct
       bpf_prog *new_prog , int *new_len , bool *seen_ld_abs );

πŸŽ€ ARGUMENTS πŸŽ€

  • prog β€” the user passed filter program. yes, the user handed this to you, be nice to it πŸ’–
  • len β€” the length of the user passed filter program. how much of it there is, basically.
  • new_prog β€” an allocated 'struct bpf_prog' or NULL. and yes, NULL is a vibe here, not a mistake (more on that in a sec πŸ‘€).
  • new_len β€” pointer to store length of converted program. you give it a pointer, it fills in the number.
  • seen_ld_abs β€” bool whether we've seen ld_abs/ind. just a little flag that remembers if that happened 🌸

πŸ”₯ DESCRIPTION πŸ”₯

the whole mission: remap the 'sock_filter' style classic BPF (cBPF) instruction set over to the 'bpf_insn' style extended BPF (eBPF). glow-up of instruction sets, no cap. ✨

here's the conversion workflow, step by step:

  1. First pass for calculating the new program length:
bpf_convert_filter(old_prog, old_len, NULL, new_len, seen_ld_abs)
  1. 2nd pass to remap in two passes: the 1st pass finds new jump offsets, then the 2nd pass does the remapping:
bpf_convert_filter(old_prog, old_len, new_prog, new_len, seen_ld_abs)

so yeah β€” one pass to size it up, then a two-pass remap to actually do the thing. it's giving "measure twice, cut once" but make it eBPF πŸ’…


πŸ‘‘ SEE ALSO πŸ‘‘

Kernel file ./net/core/filter.c β€” and bestie, the whole friend group is here too:


ngl, this page does not mention any warnings or bugs, so don't go inventing drama that isn't there πŸ™ˆ all the details above are the details, fr fr.

that's the whole page, bestie πŸŽ€ source-version-wise, this one lives in ./net/core, and it's dated October 2026 β€” bookmark it, screenshot it, put it in the group chat. slay πŸ’…πŸŒŸ

πŸ“¦ where this page comes from