Ergonomic target validation and resolution for MaeBPF kernel attachments.
{:ok, {:cgroup, "/sys/fs/cgroup/system.slice/nginx.service"}} =
MaeBPF.Target.resolve({:systemd, "nginx.service"})
{:ok, "/lib/aarch64-linux-gnu/libssl.so.3"} =
MaeBPF.Target.find_process_library(os_pid, "libssl.so")Supported targets:
:none- load without attaching:auto- auto-attach viabpf_program__attachusing ELFSEC(...)metadata{:xdp, ifspec}/{:xdp, ifspec, opts}{:tcx, ifspec, :ingress | :egress}/ withopts{:cgroup, path}|{:systemd, unit}|{:pid, os_pid}{:tracepoint, category, name}/ withopts{:raw_tracepoint, name}/ withopts{:kprobe | :kretprobe, fn_name}/ withopts{:uprobe | :uretprobe, bin_path, sym_or_off}/ withopts{:fentry | :fexit | :fmod_ret, fn_name}/ withopts{:lsm, hook}/ withopts{:freplace, target_prog_ref, fn_name}/ withopts:iter|{:iter, opts}
Summary
Functions
Extracts optional :pids from a {:tracepoint, category, name, opts} target
tuple, returning {base_target, pids_or_nil}.
Locates the full mapped path of a shared library loaded by os_pid (or :self)
by parsing /proc/<pid>/maps.
Joins a relative cgroup v2 path (such as "/system.slice/app.service" or "/")
under cgroup_root (default "/sys/fs/cgroup").
Returns true if list is a non-empty keyword list mapping hook names to
targets (for example [ingress: {:xdp, "eth0"}, egress: {:cgroup, "/sys/fs/cgroup/app"}]).
Parses /proc/<pid>/cgroup content and extracts the unified cgroup v2
relative path from the 0::<rel_path> line.
Parses /proc/<pid>/maps text and returns {:ok, full_path} for the first
mapped file whose basename starts with lib_prefix (or matches regex), or
:not_found.
Returns pre-load bpf_program__set_attach_target parameters for targets that
require setting a BTF or freplace target before bpf_object__load.
Resolves a high-level attachment target into a concrete kernel attach spec.
Returns true if term matches a recognized MaeBPF.Target tuple or :none.
Returns true if list is a non-empty list of attachment targets
(for example [{:systemd, "a.service"}, {:systemd, "b.service"}]).
Types
@type direction() :: :ingress | :egress
@type ifspec() :: String.t() | pos_integer()
@type sym_or_offset() :: String.t() | non_neg_integer()
@type t() :: :none | :auto | :iter | {:iter, keyword()} | {:xdp, ifspec()} | {:xdp, ifspec(), keyword()} | {:tcx, ifspec(), direction()} | {:tcx, ifspec(), direction(), keyword()} | {:cgroup, String.t()} | {:systemd, String.t()} | {:pid, pos_integer()} | {:tracepoint, String.t(), String.t()} | {:tracepoint, String.t(), String.t(), keyword()} | {:raw_tracepoint, String.t()} | {:raw_tracepoint, String.t(), keyword()} | {:kprobe, String.t()} | {:kprobe, String.t(), keyword()} | {:kretprobe, String.t()} | {:kretprobe, String.t(), keyword()} | {:uprobe, String.t(), sym_or_offset()} | {:uprobe, String.t(), sym_or_offset(), keyword()} | {:uretprobe, String.t(), sym_or_offset()} | {:uretprobe, String.t(), sym_or_offset(), keyword()} | {:fentry, String.t()} | {:fentry, String.t(), keyword()} | {:fexit, String.t()} | {:fexit, String.t(), keyword()} | {:fmod_ret, String.t()} | {:fmod_ret, String.t(), keyword()} | {:lsm, String.t()} | {:lsm, String.t(), keyword()} | {:freplace, freplace_target(), String.t()} | {:freplace, freplace_target(), String.t(), keyword()}
Functions
@spec extract_pids(t()) :: {t(), [pos_integer()] | pos_integer() | nil}
Extracts optional :pids from a {:tracepoint, category, name, opts} target
tuple, returning {base_target, pids_or_nil}.
@spec find_process_library(pos_integer() | :self, String.t() | Regex.t(), keyword()) :: {:ok, String.t()} | {:error, term()}
Locates the full mapped path of a shared library loaded by os_pid (or :self)
by parsing /proc/<pid>/maps.
{:ok, "/lib/aarch64-linux-gnu/libssl.so.3"} =
MaeBPF.Target.find_process_library(pid, "libssl.so")
Joins a relative cgroup v2 path (such as "/system.slice/app.service" or "/")
under cgroup_root (default "/sys/fs/cgroup").
Returns true if list is a non-empty keyword list mapping hook names to
targets (for example [ingress: {:xdp, "eth0"}, egress: {:cgroup, "/sys/fs/cgroup/app"}]).
Parses /proc/<pid>/cgroup content and extracts the unified cgroup v2
relative path from the 0::<rel_path> line.
Returns {:ok, rel_path} or {:error, :cgroup_v2_not_found}.
Parses /proc/<pid>/maps text and returns {:ok, full_path} for the first
mapped file whose basename starts with lib_prefix (or matches regex), or
:not_found.
@spec preload_attach_target(term()) :: {:ok, {non_neg_integer(), String.t()}} | :none | {:error, term()}
Returns pre-load bpf_program__set_attach_target parameters for targets that
require setting a BTF or freplace target before bpf_object__load.
{:ok, {0, "tcp_v4_connect"}} = MaeBPF.Target.preload_attach_target({:fentry, "tcp_v4_connect"})
:none = MaeBPF.Target.preload_attach_target({:kprobe, "do_sys_openat2"})
Resolves a high-level attachment target into a concrete kernel attach spec.
Options (primarily for testing or custom mount points):
:cgroup_root- cgroup v2 mount root (default"/sys/fs/cgroup"):proc_root- procfs root (default"/proc"):os_type- OS tuple override (default:os.type()):check_exists- verify cgroup directory exists on Linux (defaulttrue):dir_exists?- predicatefn path -> boolean()(default&File.dir?/1):path_exists?- predicatefn path -> boolean()(default&File.exists?/1):read_file- readerfn path -> {:ok, bin} | {:error, reason}(default&File.read/1):cmd_runner- runnerfn cmd, args, opts -> {out, status}(default&System.cmd/3)
Returns true if term matches a recognized MaeBPF.Target tuple or :none.
Returns true if list is a non-empty list of attachment targets
(for example [{:systemd, "a.service"}, {:systemd, "b.service"}]).