title | description |
---|---|
KFunc 'bpf_rdonly_cast' |
This page documents the 'bpf_rdonly_cast' eBPF kfunc, including its defintion, usage, program types that can use it, and examples. |
This kfunc tries to cast the object to a specified type.
The function returns the same obj
but with PTR_TO_BTF_ID with
btf_id. The verifier will ensure btf_id being a struct type.
Since the supported type cast may not reflect what the 'obj' represents, the returned btf_id is marked as PTR_UNTRUSTED, so the return value and subsequent pointer chasing cannot be used as helper/kfunc arguments.
#!c void *bpf_rdonly_cast(void *obj__ign, u32 btf_id__k)
This tries to support use case like below:
#!c #define skb_shinfo(SKB) ((struct skb_shared_info *)(skb_end_pointer(SKB)))
where skb_end_pointer(SKB)
is a unsigned char *
and needs to
be casted to struct skb_shared_info *
.
The following program types can make use of this kfunc:
- BPF_PROG_TYPE_CGROUP_SKB
- BPF_PROG_TYPE_CGROUP_SOCK_ADDR
- BPF_PROG_TYPE_LSM
- BPF_PROG_TYPE_LWT_IN
- BPF_PROG_TYPE_LWT_OUT
- BPF_PROG_TYPE_LWT_SEG6LOCAL
- BPF_PROG_TYPE_LWT_XMIT
- BPF_PROG_TYPE_NETFILTER
- BPF_PROG_TYPE_SCHED_ACT
- BPF_PROG_TYPE_SCHED_CLS
- BPF_PROG_TYPE_SK_SKB
- BPF_PROG_TYPE_SOCKET_FILTER
- BPF_PROG_TYPE_STRUCT_OPS
- BPF_PROG_TYPE_SYSCALL
- BPF_PROG_TYPE_TRACING
- BPF_PROG_TYPE_XDP
!!! example "Docs could be improved" This part of the docs is incomplete, contributions are very welcome