Attachment, atomic program hot-swap, iterator reads, introspection, and
teardown of kernel bpf_link resources.
{:ok, link} = MaeBPF.Link.attach_auto(obj, "on_tcp_connect")
{:ok, link} = MaeBPF.Link.attach_uprobe(obj, "on_ssl_write", libssl, "SSL_write")
{:ok, data} = MaeBPF.Link.read_iter(iter_link)
Summary
Functions
Attaches a loaded program according to a MaeBPF.Target specification.
Auto-attaches a loaded program via bpf_program__attach using its ELF
section declaration (kprobe/, kretprobe/, uprobe/, fentry/, fexit/,
fmod_ret/, lsm/, tracepoint/, raw_tp/, tp_btf/, iter/, freplace/).
Attaches a cgroup eBPF program (cgroup_skb/ingress, cgroup_skb/egress,
etc.) to a Linux cgroup v2 directory path via bpf_program__attach_cgroup.
Attaches a kprobe or kretprobe program to kernel symbol func_name.
Attaches a raw tracepoint program to tp_name via
bpf_program__attach_raw_tracepoint.
Attaches a TCX program (:ingress or :egress) to a network interface given
by name or ifindex.
Attaches a TCX program (:ingress or :egress) with explicit chain ordering
options.
Attaches a tracepoint program to <category>/<name>.
Attaches a uprobe or uretprobe program to binary_path at ELF symbol name
or byte offset sym_or_off.
Attaches an XDP program to a network interface given by name or ifindex.
Attaches an XDP program with explicit attachment mode and exclusivity guard.
Executes the XDP mode fallback and exclusivity policy against a supplied
attach_fn.(mode) callback.
Destroys a bpf_link resource handle via bpf_link__destroy.
Resolves a Linux network interface name to its positive integer ifindex.
Returns kernel metadata (id, type, type_id, prog_id) for a link.
Returns kernel metadata for a link by its kernel link ID.
Validates and normalizes attach_tcx/5 options into {:ok, {pos_atom, rel}}.
Opens an existing pinned bpf_link from path via bpf_link__open and
returns an RAII link resource handle.
Pins a bpf_link to path under /sys/fs/bpf/ via bpf_link__pin.
Returns {:ok, pin_path | nil} for a link handle.
Creates a BPF iterator stream (bpf_iter_create) on an attached iter link
and reads up to :max_bytes (default 4 MiB, max 64 MiB).
Configures a program's attach target prior to bpf_object__load via
bpf_program__set_attach_target.
Returns true if link_type supports atomic in-place BPF_LINK_UPDATE in
the Linux kernel (:xdp, :tcx, :cgroup, :netkit, :netns, :sockmap).
Unpins a previously pinned bpf_link using its recorded pin path.
Unpins a bpf_link from path under /sys/fs/bpf/ via bpf_link__unpin.
Atomically replaces the program attached to an active bpf_link via
BPF_LINK_UPDATE.
Functions
Attaches a loaded program according to a MaeBPF.Target specification.
Auto-attaches a loaded program via bpf_program__attach using its ELF
section declaration (kprobe/, kretprobe/, uprobe/, fentry/, fexit/,
fmod_ret/, lsm/, tracepoint/, raw_tp/, tp_btf/, iter/, freplace/).
{:ok, link} = MaeBPF.Link.attach_auto(obj, "on_tcp_connect")
Attaches a cgroup eBPF program (cgroup_skb/ingress, cgroup_skb/egress,
etc.) to a Linux cgroup v2 directory path via bpf_program__attach_cgroup.
Attaches a kprobe or kretprobe program to kernel symbol func_name.
{:ok, link} = MaeBPF.Link.attach_kprobe(obj, "kp_open", "do_sys_openat2")
{:ok, link} = MaeBPF.Link.attach_kprobe(obj, "krp_open", "do_sys_openat2", retprobe: true)Options:
:retprobe- boolean (defaultfalse):offset- non-negative integer byte offset intofunc_name(default0):bpf_cookie- non-negative 64-bit integer cookie (default0)
Attaches a raw tracepoint program to tp_name via
bpf_program__attach_raw_tracepoint.
{:ok, link} = MaeBPF.Link.attach_raw_tracepoint(obj, "rtp_sched", "sched_switch")
Attaches a TCX program (:ingress or :egress) to a network interface given
by name or ifindex.
Attaches a TCX program (:ingress or :egress) with explicit chain ordering
options.
Options:
:position-:last(default),:first,{:before, link_or_fd}, or{:after, link_or_fd}
Attaches a tracepoint program to <category>/<name>.
Attaches a uprobe or uretprobe program to binary_path at ELF symbol name
or byte offset sym_or_off.
{:ok, link} = MaeBPF.Link.attach_uprobe(obj, "up_ssl", "/lib/libssl.so.3", "SSL_write")
{:ok, link} = MaeBPF.Link.attach_uprobe(obj, "up_fn", "/usr/bin/app", 0x1234, pid: 4321)Options:
:pid--1(all processes, default),:self(0), or OS PID> 0:retprobe- boolean (defaultfalse):func_offset- additional byte offset whensym_or_offis a symbol name (default0):ref_ctr_offset- optional USDT semaphore offset (default0):bpf_cookie- non-negative 64-bit integer cookie (default0)
Attaches an XDP program to a network interface given by name or ifindex.
Attaches an XDP program with explicit attachment mode and exclusivity guard.
Options:
:mode-:auto(default: try:native XDP_FLAGS_DRV_MODE, falling back to:generic XDP_FLAGS_SKB_MODEon:eopnotsupp/:enotsup/:einval),:native,:generic, or:hw:exclusive-true(default) returns{:error, {:xdp_busy, message}}when another XDP program is already attached onifindexinstead of silently clobbering it;falsereturns the underlying kernel error
Executes the XDP mode fallback and exclusivity policy against a supplied
attach_fn.(mode) callback.
Destroys a bpf_link resource handle via bpf_link__destroy.
For unpinned links this detaches the program from the kernel hook. For links
pinned in /sys/fs/bpf/, only the userspace file descriptor is closed while
the pinned kernel link remains active until unpinned.
Resolves a Linux network interface name to its positive integer ifindex.
Returns kernel metadata (id, type, type_id, prog_id) for a link.
Returns kernel metadata for a link by its kernel link ID.
Validates and normalizes attach_tcx/5 options into {:ok, {pos_atom, rel}}.
Opens an existing pinned bpf_link from path via bpf_link__open and
returns an RAII link resource handle.
Pins a bpf_link to path under /sys/fs/bpf/ via bpf_link__pin.
Returns {:ok, pin_path | nil} for a link handle.
Creates a BPF iterator stream (bpf_iter_create) on an attached iter link
and reads up to :max_bytes (default 4 MiB, max 64 MiB).
{:ok, output_bin} = MaeBPF.Link.read_iter(iter_link, max_bytes: 1_048_576)
Configures a program's attach target prior to bpf_object__load via
bpf_program__set_attach_target.
Pass target_prog_fd = 0 for kernel BTF hooks (fentry, fexit,
fmod_ret, lsm) or a positive target program FD for freplace.
:ok = MaeBPF.Link.set_attach_target(obj, "my_fentry", 0, "tcp_v4_connect")
Returns true if link_type supports atomic in-place BPF_LINK_UPDATE in
the Linux kernel (:xdp, :tcx, :cgroup, :netkit, :netns, :sockmap).
true = MaeBPF.Link.supports_atomic_update?(:tcx)
false = MaeBPF.Link.supports_atomic_update?(:perf_event)
false = MaeBPF.Link.supports_atomic_update?(:tracing)
Unpins a previously pinned bpf_link using its recorded pin path.
Unpins a bpf_link from path under /sys/fs/bpf/ via bpf_link__unpin.
Atomically replaces the program attached to an active bpf_link via
BPF_LINK_UPDATE.