MaeBPF.Plug behaviour (maebpf v0.1.0)

Copy Markdown View Source

Compile-time behaviour for composable, zero-runtime-overhead eBPF pipeline plugs.

Inspired by Plug, every MaeBPF.Plug module declares pure compile-time IR emission callbacks (init/1, optional maps/1, and ir/1). During compilation (AOT via use MaeBPF or dynamically via MaeBPF.compile_pipeline/2), all plugs in a hook block are fused into a single flat eBPF instruction stream with shared packet bounds checks.

Summary

Functions

Expands a {plug_module, raw_opts} pair (or plug-expandable struct such as ~BPFC"""...""") into {maps, ops}, annotating every emitted %MaeBPF.IR.Op{} with its originating plug, file, and line.

Formats a list of integer port numbers without charlist coercion (for example, [53] renders as "[53]" instead of "~c\"5\"").

Normalizes port options (:ports, :dport, or :sport) for L4 port plugs.

Callbacks

init(opts)

@callback init(opts :: keyword()) :: term()

ir(opts)

@callback ir(opts :: term()) :: [MaeBPF.IR.Op.t()]

maps(opts)

(optional)
@callback maps(opts :: term()) :: [MaeBPF.IR.MapDef.t()]

Functions

expand(plug_mod, raw_opts \\ [], meta \\ [])

Expands a {plug_module, raw_opts} pair (or plug-expandable struct such as ~BPFC"""...""") into {maps, ops}, annotating every emitted %MaeBPF.IR.Op{} with its originating plug, file, and line.

format_ports(ports)

Formats a list of integer port numbers without charlist coercion (for example, [53] renders as "[53]" instead of "~c\"5\"").

normalize_port_opts(opts)

Normalizes port options (:ports, :dport, or :sport) for L4 port plugs.