Core DSL module that re-exports all DSL functionality.
This namespace provides a unified API for BPF program construction:
(require '[clj-ebpf.dsl.core :as dsl])
;; Build a simple XDP program that drops all packets
(def drop-all
(dsl/assemble
[(dsl/mov :r0 1) ; XDP_DROP = 1
(dsl/exit-insn)]))
For more focused imports, use the submodules directly:
Core DSL module that re-exports all DSL functionality.
This namespace provides a unified API for BPF program construction:
```clojure
(require '[clj-ebpf.dsl.core :as dsl])
;; Build a simple XDP program that drops all packets
(def drop-all
(dsl/assemble
[(dsl/mov :r0 1) ; XDP_DROP = 1
(dsl/exit-insn)]))
```
For more focused imports, use the submodules directly:
- clj-ebpf.dsl.instructions - Low-level instruction encoding
- clj-ebpf.dsl.alu - Arithmetic operations
- clj-ebpf.dsl.mem - Memory operations
- clj-ebpf.dsl.jump - Control flow
- clj-ebpf.dsl.atomic - Atomic memory operations(assemble insns)Assemble a sequence of DSL instructions into bytes.
Arguments:
Returns a byte array ready for BPF loading.
Assemble a sequence of DSL instructions into bytes. Arguments: - insns: Sequence of instruction maps (from DSL functions) Returns a byte array ready for BPF loading.
(flatten-insns insns)Flatten nested instruction sequences (e.g., from lddw).
Handles:
Flatten nested instruction sequences (e.g., from lddw). Handles: - Vectors of instructions - Single instructions - Labels
(program prog-type & body)Define a BPF program.
Example:
(program :xdp
(mov :r0 (xdp-action :pass))
(exit-insn))
Define a BPF program. Example: ```clojure (program :xdp (mov :r0 (xdp-action :pass)) (exit-insn)) ```
(resolve-labels insns)Resolve label references to actual offsets.
Arguments:
Returns a sequence of instructions with label references replaced by actual offsets.
Resolve label references to actual offsets. Arguments: - insns: Sequence of instructions (may include labels and label refs) Returns a sequence of instructions with label references replaced by actual offsets.
(sk-action action)Get socket filter action.
Get socket filter action. - :reject (0) - :accept (positive value, usually packet length)
(tc-action action)Get TC action constant.
Actions:
Get TC action constant. Actions: - :ok (0) - :reclassify (1) - :shot (2) - :pipe (3) - :stolen (4) - :queued (5) - :repeat (6) - :redirect (7)
(xdp-action action)Get XDP action constant.
Actions:
Get XDP action constant. Actions: - :aborted (0) - :drop (1) - :pass (2) - :tx (3) - :redirect (4)
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 |