Typed intermediate representation (IR) and static safety checker for MaeBPF.
A %MaeBPF.IR.Module{} describes a single eBPF ELF object containing one or
more programs (:xdp, {:tcx, :ingress | :egress},
{:tracepoint, "category/name"}) sharing module-level BPF maps.
Before lowering to eBPF ISA v3, normalize/1 and validate/1:
- Auto-register a hidden
PERCPU_ARRAYdrop counter ("__maebpf_rb_drops_<stream>",key_size: 4,value_size: 8,max_entries: 1) for every declared:ringbufstream. - Enforce the 512-byte kernel eBPF stack frame limit per program.
- Verify map references, key/value sizes,
LPM_TRIE BPF_F_NO_PREALLOC, port ranges, CIDR prefixes, and instruction/branch budgets. - Compute minimal shared packet header parsing requirements (
:eth,:ipv4,:udp,:tcp) for shared bounds-check fusion.
Summary
Functions
Constructs a %MaeBPF.IR.MapDef{} for an IPv4 or reversed-FQDN domain
allowlist (symmetric to blocklist_map/2, tagged with meta.role = :allowlist).
Analyzes a %MaeBPF.IR.Program{} to determine which packet header parsing
checks (:eth, :ipv4, :udp, :tcp) are required so the compiler can
emit shared bounds checks once at the prologue.
Constructs a %MaeBPF.IR.MapDef{} for an IPv4 (:lru_hash, :hash,
:lpm_ipv4) or reversed-FQDN domain (:lpm_domain) blocklist.
Returns the BPF_F_NO_PREALLOC flag constant (1).
Constructs a %MaeBPF.IR.MapDef{} for a counter map (:percpu_array by
default).
Returns the canonical hidden debug RingBuf drop counter map name.
Returns the canonical hidden debug RingBuf map name ("__maebpf_debug_rb").
Derives the default ELF function symbol name for a program hook and name.
Returns the hidden drop counter map ID atom for a :ringbuf stream.
Returns the canonical hidden PERCPU_ARRAY drop counter map name for a
:ringbuf stream name.
Estimates instruction and branch counts for static budget validation.
Flattens a list of IR ops including nested :scope inner ops.
Formats a single IR validation error term into a human-readable message.
Returns the kernel bpf_map_type integer for a supported IR map kind.
Returns the maximum eBPF stack frame size in bytes (512).
Normalizes a %MaeBPF.IR.Module{}
Returns true when program has tracepoint PID filtering enabled.
Constructs the hidden HASH map definition (4B u32 PID -> 4B u32) used to
filter tracepoint invocations to selected OS PIDs.
Returns the canonical hidden tracepoint OS PID filter HASH map name.
Returns the canonical hidden per-CPU sampling sequence counter map name.
Derives the canonical libbpf ELF section name for a program hook.
Constructs the hidden 5-tuple LRU_HASH flow verdict cache (key_size: 12,
value_size: 4) used by MaeBPF.Plugs.TLSSNI.
Returns the canonical hidden LRU_HASH 5-tuple flow cache map name used by :tls_sni.
Constructs the hidden PERCPU_ARRAY scratch buffer map (value_size: 2304,
max_entries: 1) used by MaeBPF.Plugs.TLSSNI.
Returns the canonical hidden PERCPU_ARRAY scratch map name used by :tls_sni.
Computes exact kernel stack bytes required by program within ir_module.
Constructs a %MaeBPF.IR.MapDef{} for a RingBuf event stream.
Validates a %MaeBPF.IR.Module{} statically.
Like validate/2, returning the normalized %MaeBPF.IR.Module{} or raising
ArgumentError with a detailed validation report.
Returns a copy of ir configured for live zero-downtime debug tracing.
Returns a copy of ir with tracepoint PID filtering enabled on all
tracepoint programs, injecting the hidden "__maebpf_pid_filter" HASH map.
Functions
Constructs a %MaeBPF.IR.MapDef{} for an IPv4 or reversed-FQDN domain
allowlist (symmetric to blocklist_map/2, tagged with meta.role = :allowlist).
Analyzes a %MaeBPF.IR.Program{} to determine which packet header parsing
checks (:eth, :ipv4, :udp, :tcp) are required so the compiler can
emit shared bounds checks once at the prologue.
Constructs a %MaeBPF.IR.MapDef{} for an IPv4 (:lru_hash, :hash,
:lpm_ipv4) or reversed-FQDN domain (:lpm_domain) blocklist.
Returns the BPF_F_NO_PREALLOC flag constant (1).
Constructs a %MaeBPF.IR.MapDef{} for a counter map (:percpu_array by
default).
Returns the canonical hidden debug RingBuf drop counter map name.
Returns the canonical hidden debug RingBuf map name ("__maebpf_debug_rb").
Derives the default ELF function symbol name for a program hook and name.
Returns the hidden drop counter map ID atom for a :ringbuf stream.
Returns the canonical hidden PERCPU_ARRAY drop counter map name for a
:ringbuf stream name.
Estimates instruction and branch counts for static budget validation.
Flattens a list of IR ops including nested :scope inner ops.
Formats a single IR validation error term into a human-readable message.
Returns the kernel bpf_map_type integer for a supported IR map kind.
Returns the maximum eBPF stack frame size in bytes (512).
Normalizes a %MaeBPF.IR.Module{}:
- Fills missing
name,section,c_name, andLPM_TRIE BPF_F_NO_PREALLOC. - Assigns stable 1-based
plug_idindices per program when unset. - Auto-injects hidden
"__maebpf_rb_drops_<stream>" PERCPU_ARRAYmaps for every declared:ringbufstream. - Auto-injects hidden
"__maebpf_sample_cnt" PERCPU_ARRAYwhen any op uses sampling (every > 1) ordebug_traceusessample > 1.
Returns true when program has tracepoint PID filtering enabled.
Constructs the hidden HASH map definition (4B u32 PID -> 4B u32) used to
filter tracepoint invocations to selected OS PIDs.
Returns the canonical hidden tracepoint OS PID filter HASH map name.
Returns the canonical hidden per-CPU sampling sequence counter map name.
Derives the canonical libbpf ELF section name for a program hook.
Constructs the hidden 5-tuple LRU_HASH flow verdict cache (key_size: 12,
value_size: 4) used by MaeBPF.Plugs.TLSSNI.
Returns the canonical hidden LRU_HASH 5-tuple flow cache map name used by :tls_sni.
Constructs the hidden PERCPU_ARRAY scratch buffer map (value_size: 2304,
max_entries: 1) used by MaeBPF.Plugs.TLSSNI.
Returns the canonical hidden PERCPU_ARRAY scratch map name used by :tls_sni.
Computes exact kernel stack bytes required by program within ir_module.
Constructs a %MaeBPF.IR.MapDef{} for a RingBuf event stream.
Validates a %MaeBPF.IR.Module{} statically.
Options:
:max_stack_bytes- default512:max_instructions- default4096:max_branches- default512:debug_trace- validate including debug-trace overhead
Returns {:ok, normalized_ir} or {:error, [reason, ...]}.
Like validate/2, returning the normalized %MaeBPF.IR.Module{} or raising
ArgumentError with a detailed validation report.
Returns a copy of ir configured for live zero-downtime debug tracing.
Injects the hidden "__maebpf_debug_rb" :ringbuf stream, its hidden
"__maebpf_rb_drops___maebpf_debug_rb" drop counter, and sets
meta[:debug_trace] and meta[:debug_sample].
Returns a copy of ir with tracepoint PID filtering enabled on all
tracepoint programs, injecting the hidden "__maebpf_pid_filter" HASH map.