Unified compile-time DSL backing use MaeBPF.
One Elixir module compiles to one multi-program, multi-map little-endian
bpfel ELF64 object embedded directly into the .beam at mix compile time
(on both macOS and Linux with zero clang dependency).
Example:
defmodule MyEdge.Gateway do
use MaeBPF
counter :blocked_dns
blocklist :bad_ips, type: :lpm_ipv4, max_entries: 10_000
stream :alerts, ringbuf_kb: 256
xdp :ingress do
plug MaeBPF.Plugs.DropInvalid
drop ipv4(src_in: :bad_ips), count: :blocked_dns
drop udp(dport: 53), count: :blocked_dns, emit: :alerts
pass tcp(dport: 443)
default :pass
end
tcx :egress, direction: :egress do
drop tcp(dport: 25)
default :pass
end
end
Summary
Functions
Declares a module-level IPv4 or domain allowlist map
(type: :lpm_domain | :lpm_ipv4 | :lru_hash | :hash).
Declares a module-level IPv4 or domain blocklist map
(type: :lpm_ipv4 | :lpm_domain | :lru_hash | :hash).
Declares a custom BPF map using explicit %MaeBPF.IR.MapDef{} fields.
Declares module-level C code (structs, static __always_inline helpers, or
extern declarations) emitted before hook functions in use MaeBPFC modules.
Declares a Linux cgroup v2 cgroup_skb hook block (direction: :ingress | :egress).
Declares a module-level counter map (:percpu_array by default, key: u32,
value: u64).
Sets the default fallback action (:pass, :drop, :tx, :next, etc.) for
packets that reach the end of the current hook pipeline.
Declarative drop rule sugar inside a hook block
Declares a typed eBPF global variable in .rodata (readonly: true, default)
or .data/.bss (readonly: false) for use MaeBPFC modules.
Declarative pass rule sugar inside a hook block
Appends a MaeBPF.Plug module to the current hook pipeline.
Scopes a block of packet rules to matching L4 ports and/or protocol inside an
xdp, tcx, or cgroup hook block.
Declares a module-level RingBuf event stream (ringbuf_kb: default 256).
IR normalization automatically registers "__maebpf_rb_drops_<name>".
Declares a tcx program hook block (direction: :ingress | :egress).
Declares a kernel tracepoint hook block.
Declares an xdp program hook block sharing all module-level maps.
Functions
Declares a module-level IPv4 or domain allowlist map
(type: :lpm_domain | :lpm_ipv4 | :lru_hash | :hash).
allowlist :allowed_domains, type: :lpm_domain, max_entries: 10_000
Declares a module-level IPv4 or domain blocklist map
(type: :lpm_ipv4 | :lpm_domain | :lru_hash | :hash).
Declares a custom BPF map using explicit %MaeBPF.IR.MapDef{} fields.
Declares module-level C code (structs, static __always_inline helpers, or
extern declarations) emitted before hook functions in use MaeBPFC modules.
c_preamble ~BPFC"""
static __always_inline int is_watched(__u16 port) {
return port == target_port;
}
"""
Declares a Linux cgroup v2 cgroup_skb hook block (direction: :ingress | :egress).
Compiles to ELF section "cgroup_skb/ingress" or "cgroup_skb/egress" with
L3 IPv4 packet offsets (no 14-byte Ethernet header) and cgroup_skb verdicts
(1 = :pass, 0 = :drop).
Declares a module-level counter map (:percpu_array by default, key: u32,
value: u64).
Sets the default fallback action (:pass, :drop, :tx, :next, etc.) for
packets that reach the end of the current hook pipeline.
Declarative drop rule sugar inside a hook block:
drop :invalid->MaeBPF.Plugs.DropInvaliddrop udp(dport: 53), count: :c, emit: :s->MaeBPF.Plugs.DropUDPdrop tcp(dport: 25), count: :c, emit: :s->MaeBPF.Plugs.DropTCPdrop ipv4(src_in: :bad_ips), count: :c, emit: :s->MaeBPF.Plugs.Blocklist
Declares a typed eBPF global variable in .rodata (readonly: true, default)
or .data/.bss (readonly: false) for use MaeBPFC modules.
global :target_comm, {:string, 16}, default: "curl"
global :target_port, :u32, default: 443
global :watch_ports, {:array, :u16, 4}, default: [80, 443, 8080, 8443]
global :magic_hdr, {:bytes, 4}, default: <<0xDE, 0xAD, 0xBE, 0xEF>>
global :debug_mode, :bool, default: false, readonly: falseSupported types: :bool, :u8, :u16, :u32, :u64, :i8, :i16,
:i32, :i64, :be16, :be32, :be64, :ipv4, :ipv6, :mac,
{:string, n}, {:bytes, n}, and {:array, elem_type, n}.
Declarative pass rule sugar inside a hook block:
pass udp(dport: 443), count: :c, emit: :s->MaeBPF.Plugs.PassUDPpass tcp(dport: 443), count: :c, emit: :s->MaeBPF.Plugs.PassTCPpass ipv4(src_in: :allowlist), count: :c, emit: :s->MaeBPF.Plugs.Blocklist(action: :pass)
Appends a MaeBPF.Plug module to the current hook pipeline.
Scopes a block of packet rules to matching L4 ports and/or protocol inside an
xdp, tcx, or cgroup hook block.
Packets that do not match the scope guard skip every rule inside the block
untouched and continue to subsequent rules or default.
Options:
:ports- integer port or list of ports in1..65535(also accepts:dportor:sportshorthands):proto-:any(default, matching TCP or UDP),:tcp, or:udp:match-:dport(default),:sport, or:either
Declares a module-level RingBuf event stream (ringbuf_kb: default 256).
IR normalization automatically registers "__maebpf_rb_drops_<name>".
Declares a tcx program hook block (direction: :ingress | :egress).
Declares a kernel tracepoint hook block.
Target may be a "category/name" string or keyword options
[tracepoint: "category/name"] / [category: "syscalls", name: "sys_enter_openat"].
Pass filter_pids: true or pids: [os_pid, ...] to compile in an entry PID
filter backed by the hidden "__maebpf_pid_filter" HASH map.
Declares an xdp program hook block sharing all module-level maps.