clj-ebpf is a pure Clojure library for working with Linux eBPF (Extended Berkeley Packet Filter). It provides a high-level DSL for writing BPF programs, manages BPF maps, and handles program loading and attachment - all without requiring external C toolchains.
(require '[clj-ebpf.core :as bpf]
'[clj-ebpf.dsl.core :as dsl])
;; Initialize the library
(bpf/init!)
;; Create a simple XDP program that passes all packets
(def pass-all
(dsl/assemble
[(dsl/mov :r0 2) ; XDP_PASS = 2
(dsl/exit-insn)]))
;; Load the program
(def prog-fd (bpf/load-program pass-all :xdp))
;; Clean up when done
(bpf/close-program prog-fd)
| Module | Description |
|---|---|
clj-ebpf.core | Main entry point, initialization |
clj-ebpf.maps | BPF map creation and manipulation |
clj-ebpf.programs | Program loading and attachment |
clj-ebpf.events | Ring buffer and perf event handling |
| Module | Description |
|---|---|
clj-ebpf.dsl.core | Unified DSL API |
clj-ebpf.dsl.alu | Arithmetic operations |
clj-ebpf.dsl.mem | Memory operations |
clj-ebpf.dsl.jump | Control flow |
clj-ebpf.dsl.atomic | Atomic operations |
clj-ebpf.dsl.instructions | Low-level encoding |
| Module | Description |
|---|---|
clj-ebpf.xdp | XDP program attachment |
clj-ebpf.tc | Traffic Control (TC) programs |
clj-ebpf.cgroup | Cgroup programs |
clj-ebpf.lsm | Linux Security Modules |
clj-ebpf.perf | Perf event programs |
| Module | Description |
|---|---|
clj-ebpf.helpers | BPF helper function metadata |
clj-ebpf.errors | Structured error handling |
clj-ebpf.arch | Multi-architecture support |
clj-ebpf.constants | BPF constants and flags |
clj-ebpf.utils | Memory utilities |
clj-ebpf supports multiple CPU architectures:
The library automatically detects the architecture and uses appropriate syscall numbers.
Can you improve this documentation?Edit on GitHub
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |