Managed Atomic eBPF (maeBPF): zero-clang pure-Elixir eBPF compilation,
compile-time fused MaeBPF.Plug pipelines, state-preserving atomic
BPF_LINK_UPDATE hot-swapping, and zero-polling enif_select ring buffer
streaming for Elixir/BEAM.
Use use MaeBPF inside an Elixir module to declare shared maps and hook
blocks (xdp, tcx, trace) that AOT-compile into a single little-endian
bpfel ELF64 object embedded directly into .beam on both macOS and Linux.
Top-level public facade delegating to:
MaeBPF.DSL- unifieduse MaeBPFmacro DSL and AOT ELF embeddingMaeBPF.IR- typed multi-program IR, static safety checker, and header analysisMaeBPF.Plug- compile-time fused eBPF plug behaviour and built-inMaeBPF.Plugs.*MaeBPF.Compiler.Pure- zero-clangpure-Elixir eBPF ISA v3 + ELF64 + BTF compilerMaeBPF.Sim&MaeBPF.Packet- cross-platform macOS/Linux IR simulator and packet buildersMaeBPF.Test&MaeBPF.TestRun- dual-mode simulator + LinuxBPF_PROG_TEST_RUNharnessMaeBPF.Schema&MaeBPF.Migration- packed binary codecs and live map schema migrationMaeBPF.Probe- Linux kernel version, BTF/JIT, privilege, and feature probingMaeBPF.Disasm&MaeBPF.Diagnostics- eBPF ISA disassembler and source-mapped verifier errorsMaeBPF.Server- OTP GenServer managing object, links, ringbuf, debug tracing, and hot-swapMaeBPF.Map- kernel BPF map operations, per-CPU maps, LPM tries, pinning, and FD reuseMaeBPF.Link- XDP, TCX, and tracepointbpf_linkattachment, pinning, and updatesMaeBPF.RingBuf- zero-polling bounded and packedenif_selectring buffer consumerMaeBPF.Telemetry-bpftool-parity runtime stats, bytecode dump, and kernel ID enumeration
When the optional :maebpf_c companion package is installed, compile_c/2,
compile_c_timed/2, ensure_vmlinux_h/1, and {:c, source} /
{:c_source, source} inputs automatically dispatch to MaeBPF.Compiler.C.
Summary
Functions
Starts a linked MaeBPF.Supervisor supervising a list of policy child specs.
Attaches either
Compiles (if needed), loads, and attaches an eBPF policy or program.
Explicitly closes an eBPF object resource.
Compiles C eBPF source via the optional :maebpf_c companion package.
Compiles C eBPF source and returns elapsed microseconds via the optional
:maebpf_c companion package.
Dynamically fuses and compiles a runtime list of MaeBPF.Plug specifications
(PlugMod or {PlugMod, opts}) into an ELF64 binary, validated IR, and
instruction source map in sub-millisecond time with zero clang.
Detaches a running policy server or MaeBPF.Supervisor cleanly.
Disables kernel BPF_STATS_RUN_TIME either for a raw RAII stats guard handle
or dynamically on a running MaeBPF.Server.
Enables kernel BPF_STATS_RUN_TIME globally and returns an RAII guard handle.
Dynamically enables kernel BPF_STATS_RUN_TIME on a running MaeBPF.Server
without reloading the eBPF program.
Ensures a cached kernel vmlinux.h header via the optional :maebpf_c
companion package.
Reads and decodes a BTF-described global variable from a loaded object or
running MaeBPF.Server.
Reads and decodes all BTF-described global variables from a loaded object or
running MaeBPF.Server.
Returns a structured inspection summary of a use MaeBPF module,
%MaeBPF.IR.Module{}, or compiled result map for IEx introspection.
Loads an opened eBPF object into the Linux kernel via bpf_object__load.
Deletes an exact or wildcard FQDN rule from a reversed-FQDN LPM_TRIE map.
Deletes a program entry from a BPF_MAP_TYPE_PROG_ARRAY slot.
Reads the kernel program ID stored in a BPF_MAP_TYPE_PROG_ARRAY slot.
Inserts an exact ("evil.example.com") or wildcard ("*.blocked.org") FQDN
rule into a reversed-FQDN LPM_TRIE map.
Inserts a program into a BPF_MAP_TYPE_PROG_ARRAY slot on an object or
running MaeBPF.Server.
Opens an eBPF ELF64 binary in memory via bpf_object__open_mem.
Dumps kernel xlated and jited bytecode for a loaded eBPF object and
program name (MaeBPF.Telemetry.prog_dump/2), or from a running
MaeBPF.Server (MaeBPF.Server.prog_dump/2).
Returns the loaded kernel program file descriptor for an object or running
MaeBPF.Server.
Updates a mutable (.data or .bss) global variable on a loaded object or
running MaeBPF.Server. Rejects .rodata writes with
{:error, {:readonly_global, name, hint}}.
Reads output from an attached BPF iterator link (iter/) via
bpf_iter_create.
Executes a test packet against either a loaded kernel object (MaeBPF.TestRun)
or a use MaeBPF module / %MaeBPF.IR.Module{} (MaeBPF.Test).
Functions
Starts a linked MaeBPF.Supervisor supervising a list of policy child specs.
Accepts standard OTP child specs ({MyPolicy, target: ...}) as well as
concise target shorthands ({MyPolicy, {:xdp, "eth0"}},
{MyPolicy, {:cgroup, "/sys/fs/cgroup/app"}}, {MyPolicy, {:systemd, "app.service"}}).
Call MaeBPF.detach/1 on the returned supervisor PID to stop all children
and automatically detach every unpinned kernel link.
Attaches either:
- A list of supervised policy children with supervisor options
(
MaeBPF.attach(children, strategy: :one_for_one, name: MySup)) - A single policy/source to one target, a list of targets (starts a
MaeBPF.Supervisorrunning one worker per target), or a keyword/map of named hooks for a multi-hook module (starts oneMaeBPF.Server)
Compiles (if needed), loads, and attaches an eBPF policy or program.
source may be a use MaeBPF module, a %MaeBPF.IR.Module{}, a compiled
ELF binary, {:elf, bin}, {:pure_spec, spec}, {:c, src} /
{:c_source, src} (requires optional :maebpf_c), or a keyword option list.
attach_spec may be:
:none{:xdp, ifname_or_index}or{:xdp, ifname_or_index, xdp_opts}{:tcx, ifname_or_index, :ingress | :egress}or withtcx_opts{:cgroup, cgroup_path}{:systemd, unit_name}(resolves unified cgroup v2 path){:pid, os_pid}(resolves unified cgroup v2 path){:tracepoint, category, name}or{:tracepoint, category, name, opts}- A list of multiple targets (
[{:systemd, "a.service"}, {:systemd, "b.service"}]), starting a linkedMaeBPF.Supervisorwith one isolated worker per target - A keyword list or map of named hooks for one multi-hook module
(
[ingress: {:xdp, "veth0"}, egress: {:cgroup, "/sys/fs/cgroup/app"}]), starting oneMaeBPF.Serversharing a single kernel object and maps
Explicitly closes an eBPF object resource.
Compiles C eBPF source via the optional :maebpf_c companion package.
Returns {:error, {:missing_optional_package, :maebpf_c, ...}} when
:maebpf_c is not installed.
Compiles C eBPF source and returns elapsed microseconds via the optional
:maebpf_c companion package.
Returns {:error, {:missing_optional_package, :maebpf_c, ...}} when
:maebpf_c is not installed.
Dynamically fuses and compiles a runtime list of MaeBPF.Plug specifications
(PlugMod or {PlugMod, opts}) into an ELF64 binary, validated IR, and
instruction source map in sub-millisecond time with zero clang.
Options:
:hook-:xdp(default),{:tcx, :ingress | :egress}, or{:tracepoint, "category/name"}:name- program atom name (default:pipeline):prog_name- ELF function symbol name:default- fallback action (default:pass):maps- explicit list of%MaeBPF.IR.MapDef{}:license- ELF license string (default"GPL"):debug_trace- enable per-plug debug RingBuf tracing (defaultfalse):sample- debug trace sampling interval (default1)
Detaches a running policy server or MaeBPF.Supervisor cleanly.
Stops the target process (or supervisor tree in reverse child order),
immediately detaching every unpinned kernel bpf_link.
Disables kernel BPF_STATS_RUN_TIME either for a raw RAII stats guard handle
or dynamically on a running MaeBPF.Server.
Enables kernel BPF_STATS_RUN_TIME globally and returns an RAII guard handle.
Dynamically enables kernel BPF_STATS_RUN_TIME on a running MaeBPF.Server
without reloading the eBPF program.
Ensures a cached kernel vmlinux.h header via the optional :maebpf_c
companion package.
Returns {:error, {:missing_optional_package, :maebpf_c, ...}} when
:maebpf_c is not installed.
Reads and decodes a BTF-described global variable from a loaded object or
running MaeBPF.Server.
{:ok, true} = MaeBPF.get_global(srv, :enabled)
Reads and decodes all BTF-described global variables from a loaded object or
running MaeBPF.Server.
{:ok, %{"enabled" => true}} = MaeBPF.get_globals(srv)
Returns a structured inspection summary of a use MaeBPF module,
%MaeBPF.IR.Module{}, or compiled result map for IEx introspection.
Loads an opened eBPF object into the Linux kernel via bpf_object__load.
Deletes an exact or wildcard FQDN rule from a reversed-FQDN LPM_TRIE map.
:ok = MaeBPF.map_delete_domain(srv, "blocked_domains", "*.blocked.org")
Deletes a program entry from a BPF_MAP_TYPE_PROG_ARRAY slot.
:ok = MaeBPF.map_delete_prog(srv, "jump_table", 0)
Reads the kernel program ID stored in a BPF_MAP_TYPE_PROG_ARRAY slot.
{:ok, prog_id} = MaeBPF.map_lookup_prog_id(srv, "jump_table", 0)
Inserts an exact ("evil.example.com") or wildcard ("*.blocked.org") FQDN
rule into a reversed-FQDN LPM_TRIE map.
:ok = MaeBPF.map_put_domain(srv, "blocked_domains", "*.blocked.org")
Inserts a program into a BPF_MAP_TYPE_PROG_ARRAY slot on an object or
running MaeBPF.Server.
:ok = MaeBPF.map_put_prog(srv, "jump_table", 0, "tail_handler")
Opens an eBPF ELF64 binary in memory via bpf_object__open_mem.
Dumps kernel xlated and jited bytecode for a loaded eBPF object and
program name (MaeBPF.Telemetry.prog_dump/2), or from a running
MaeBPF.Server (MaeBPF.Server.prog_dump/2).
Returns the loaded kernel program file descriptor for an object or running
MaeBPF.Server.
{:ok, fd} = MaeBPF.prog_fd(srv, "xdp_main")
Updates a mutable (.data or .bss) global variable on a loaded object or
running MaeBPF.Server. Rejects .rodata writes with
{:error, {:readonly_global, name, hint}}.
:ok = MaeBPF.put_global(srv, :enabled, false)
Reads output from an attached BPF iterator link (iter/) via
bpf_iter_create.
{:ok, data} = MaeBPF.read_iter(srv, max_bytes: 1_048_576)
See MaeBPF.Sim.run/4.
See MaeBPF.Server.stop/2.
Executes a test packet against either a loaded kernel object (MaeBPF.TestRun)
or a use MaeBPF module / %MaeBPF.IR.Module{} (MaeBPF.Test).