Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Appendix A - Aya & eBPF API Reference

A compact reference for the names that recur through the book. The Aya version referenced throughout is the 0.13 line (aya and aya-bpf crates at 0.13.x); where the API differs in newer versions, the book’s comments say so. Check the crate docs for the exact signatures of your pinned version.

Userspace (aya crate)

ItemPurposeBook chapter
Ebpf::load(&[u8])Load an ELF object containing BPF programs and maps3
Ebpf::programs()Iterate over loaded programs by name3
Ebpf::map(name)Fetch a map handle from the loaded object3, 4
Ebpf::attach / program.attach(...)Attach a program to its hook3, 5, 6
programs::Xdp + attach(iface, XdpFlags)Attach an XDP program to an interface5
programs::SchedClassifier / SchedClassifierAttachModeAttach a tc program (clsact)6
programs::SockMap / SockHashAttach sk_msg / sk_skb programs to a sockmap8
programs::CgroupSkb / CgroupSockAddr / CgroupSockoptcgroup-bound programs9
programs::KProbe / programs::TracePointkprobe / tracepoint programs7, 15
maps::HashMap<K, V>Hash map, the workhorse4
maps::PerCpuHashMap<K, V>Per-CPU hash map4, 13
maps::Array<T> / maps::PerCpuArray<T>Indexed array maps4
maps::LruHashMap<K, V>LRU-evicting hash map4, 16
maps::RingBufLock-free ring buffer for events4, 12, 16
maps::SockHash / maps::SockMapSocket maps for redirect8, 16
maps::MapDataRaw map handle for advanced use4
BpfError, ProgramError, MapErrorError types; always check and log3, 14

Kernel side (aya-bpf crate)

ItemPurposeBook chapter
programs::XdpContextXDP program context: data, data_end5
programs::SchedClassifierContexttc program context6
programs::SkMsgContextsk_msg program context8
programs::SkSkbContextsk_skb program context8
programs::CgroupSkbContextcgroup socket filter context9
programs::KProbeContextkprobe context (pt_regs)7, 15
maps::{HashMap, PerCpuHashMap, Array, RingBuf, LruHashMap}Kernel-side map views4
helpers::bpf_redirect, bpf_redirect_mapPacket redirect helpers5, 6
helpers::bpf_skb_load_bytes, bpf_skb_store_bytesSafe packet read/write6
helpers::bpf_get_current_pid_tgid, bpf_get_current_commTask identity9, 15
helpers::bpf_ktime_get_nsKernel timestamp (ktime)13
bindings::{ethhdr, iphdr, tcphdr, udphdr}Network header structs (libc-style)5, 8
ctx::XdpContext::data() / data_end()Bounds-checked packet access5

Kernel constants worth remembering

ConstantValueMeaning
XDP_DROP1drop the packet in the driver
XDP_PASS2hand the packet to the stack
XDP_TX3transmit out the same interface
XDP_REDIRECT4redirect via bpf_redirect_map
BPF_F_INGRESS1tc/sockmap ingress direction flag
TC_ACT_OK / TC_ACT_SHOT0 / 2tc accept / drop
BPF_MAP_TYPE_RINGBUF27ring buffer map type id
BPF_MAXINSNS1,000,000verifier instruction limit (6.x)
BPF_MAX_LOOPS8,388,608verifier loop bound (6.x)

The three syscalls that matter

Everything eBPF goes through bpf(2), and everything you attach to goes through the usual suspects:

SyscallUsed for
bpf(BPF_PROG_LOAD, ...)load and verify a program
bpf(BPF_MAP_CREATE, ...)create a map
bpf(BPF_PROG_ATTACH, ...) / BPF_LINK_CREATEattach a program to a hook
perf_event_open + io_uring (Chapter 12)the I/O plumbing around eBPF in real services

All of them are wrapped by Aya; you will only meet the raw syscalls when debugging with strace or reading bpftool output (Chapter 14).