bpf_ksock_create(9)
π bpf_ksock_create(9) π
okay so bestie, welcome to the Kernel API Manual for bpf_ksock_create(9) β yes we're reading kernel docs together, this is our bonding time now π«Ά
β¨ NAME β¨
bpf_ksock_create β the one that creates a BPF kernel socket, no cap π§
β¨ SYNOPSIS β¨
__bpf_kfunc struct bpf_ksock * bpf_ksock_create (const struct
bpf_ksock_create_opts *opts , u32 opts__sz , int *err__uninit );
like, look at that signature. iconic behavior honestly π
β¨ ARGUMENTS β¨
optsβ pointer to astruct bpf_ksock_create_optsholding all the socket parameters. it's giving "here's my whole configuration bestie" πopts__szβ the size of theoptsstruct, au32. yes you gotta tell it how big your struct is, standard stuff πerr__uninitβ an integer where the error code gets stashed wheneverNULLis returned. so like, if it hands you back nothing, check here for the tea π
β¨ DESCRIPTION β¨
so what it does is allocate and create a kernel socket. literally the whole vibe β¨
the context you get back must either be:
- stored in a map as a
kptr, or - freed with
bpf_ksock_release
no third option, no "i'll deal with it later" β those are the only two paths periodt π
β οΈ heads up bestie: this function may sleep (sock_create), which means it can only be used in sleepable BPF programs (SYSCALL). and nope, you cannot call it from a BPF workqueue callback, because that callback does not retain the invoking task's namespace or security context. so like, don't even try it π
β¨ SEE ALSO β¨
go check out the kernel file ./net/core/bpf_ksock.c and these besties:
struct bpf_ksock(9)bpf_ksock_connect(9)bpf_ksock_acquire(9)bpf_ksock_release(9)bpf_ksock_send(9)
they're all in the group chat, fr fr πΈ
k bye ily, this page lives in ./net/core, dated October 2026, and it's from the Kernel API Manual β go read the source, it ate πβ¨ππ¦
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms