luaebpf

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.

A layout comes back in the shape 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 bigendian when its type is a __be16, __be32 or __be64, which struct packs and reads big-endian; a __sum16 is not. A bitfield of an integer type is reported in bitfields, 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 the shift and mask that 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_ptr members, and a nested struct, are absent, and struct reads the gap they and the bitfields leave as padding.

Parameters

  • what string the struct’s name, as bpftool btf dump prints it

Returns

    table {size = bytes, fields = {{name, offset, size, signed, bigendian}, ...}, bitfields = {{name, offset, size, signed, shift, mask}, ...}}, offsets and sizes in bytes

Raises

<path>: <reason>, when the BTF file cannot be read, <path> carries no BTF header, <path> is shorter than its BTF header says, and the kernel BTF has no struct '<what>'
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. The file is read when a layout is first asked for.

Parameters

  • path string the file, /sys/kernel/btf/vmlinux when absent (optional)