bpf.vmlinuxModule
The kernel’s own type information, read from a raw BTF file: /sys/kernel/btf/vmlinux, the
running kernel’s, unless luaebpf.compile is handed the BTF of the kernel it compiles for.
autogen emits and struct consumes, so a kernel struct
becomes a codec, a map value spec or a set of context offsets with nothing transcribed from a
header. BTF records no member’s byte offset directly: the file is a flat stream of
variable-length records naming each other by type id, so one pass records where every id
starts and a struct’s members resolve in constant time afterwards.
Usage
local vmlinux = require("bpf.vmlinux")
local struct = require("struct")
local skb = struct(vmlinux.layout("__sk_buff"))
Functions
| bpf.vmlinux.check (bigendian) | Refuses the BTF a layout was read from when it is not in the object’s byte order, since it then describes another kernel than the one the object is for. |
| bpf.vmlinux.layout (what) | The layout of a kernel struct. |
| bpf.vmlinux.open ([path]) | Reads the layouts from the raw BTF file at path from then on, the bytes
/sys/kernel/btf/vmlinux serves, in the byte order its magic is written in. |
Functions in detail
- bpf.vmlinux.check (bigendian)
-
Refuses the BTF a layout was read from when it is not in the object’s byte order, since it then
describes another kernel than the one the object is for.
Parameters
- bigendian boolean whether the object is big-endian
Raises
<path> is a <order>-endian BTF, for a <order>-endian object - bpf.vmlinux.layout (what)
-
The layout of a kernel struct.
A member is reported when its type resolves to an integer of a whole number of bytes at a byte-aligned offset, and marked
bigendianwhen its type is a__be16,__be32or__be64, whichstructpacks and reads big-endian; a__sum16is not. A bitfield of an integer type is reported inbitfields, with the load that covers it, the narrowest naturally aligned one of its type’s size or wider, as libbpf’s CO-RE relocations read it, and theshiftandmaskthat take it out of that load, for the BTF’s byte order; one no load of eight bytes covers is absent. A union such as__sk_buff’s__bpf_md_ptrmembers, and a nested struct, are absent, andstructreads the gap they and the bitfields leave as padding.Parameters
- what
string
the struct’s name, as
bpftool btf dumpprints it
Returns
-
table
{size = bytes, fields = {{name, offset, size, signed, bigendian}, ...}, bitfields = {{name, offset, size, signed, shift, mask}, ...}}, offsets and sizes in bytesRaises
<path>: <reason>, when the BTF file cannot be read,<path> carries no BTF header,<path> is shorter than its BTF header says, andthe kernel BTF has no struct '<what>' - what
string
the struct’s name, as
- bpf.vmlinux.open ([path])
-
Reads the layouts from the raw BTF file at
pathfrom then on, the bytes/sys/kernel/btf/vmlinuxserves, in the byte order its magic is written in. The file is read when a layout is first asked for.Parameters
- path
string
the file,
/sys/kernel/btf/vmlinuxwhen absent (optional)
- path
string
the file,