Skip to content

Latest commit

 

History

History
64 lines (47 loc) · 2.48 KB

bpf_rdonly_cast.md

File metadata and controls

64 lines (47 loc) · 2.48 KB
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.

KFunc bpf_rdonly_cast

:octicons-tag-24: v6.2

Definition

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)

Usage

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 *.

Program types

The following program types can make use of this kfunc:

Example

!!! example "Docs could be improved" This part of the docs is incomplete, contributions are very welcome