Accepted
BPF programs are typically written in C and compiled with LLVM/Clang to BPF bytecode. However, this requires:
We wanted to provide a way to write BPF programs directly in Clojure without external tools.
We created a DSL (Domain Specific Language) that:
:r0, :r1), vectors for instruction sequencesclj-ebpf.dsl.instructions - Raw instruction encodingclj-ebpf.dsl.alu, .mem, .jump, .atomic - Categorized operationsclj-ebpf.dsl.core - Unified API with assemble functionExample:
(require '[clj-ebpf.dsl.core :as dsl])
(def program
(dsl/assemble
[(dsl/mov :r0 2) ; Set return value
(dsl/exit-insn)])) ; Exit program
We chose transparency over abstraction. The DSL shows exactly what BPF instructions are generated, which helps with debugging verifier errors. Higher-level abstractions can be built on top.
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 |