Skip to content

KFunc bpf_ksock_release

v7.3

Release a BPF kernel socket.

Definition

Releases a reference to a BPF kernel socket context. When the final reference has been released, the socket is closed and the context is freed. Since closing a socket may sleep, this cleanup is deferred to a work-queue after an RCU grace period, so this kfunc itself does not sleep.

ks: The BPF kernel socket context to release.

Signature

void bpf_ksock_release(struct bpf_ksock *ks)

Note

This kfunc releases the pointer passed in to it. There can be only one referenced pointer that can be passed in. All copies of the pointer being released are invalidated as a result of invoking this kfunc.

Usage

This kfunc is used to release a reference held on a BPF kernel socket context, previously acquired using bpf_ksock_create or bpf_ksock_acquire, or taken out of a map with bpf_kptr_xchg.

When a map value containing a BPF kernel socket kptr is deleted, or the map itself is freed, the kernel automatically calls this kfunc to release the reference held by the map.

Warning

This kfunc can't be used by LSM programs attached to the socket_sendmsg hook. Since bpf_ksock_send invokes this hook, such programs could cause infinite recursion. The verifier rejects such programs with the message calling kernel function bpf_ksock_release is not allowed.

Program types

The following program types can make use of this kfunc:

Example

See bpf_ksock_create for an example.