Liking cljdoc? Tell your friends :D

clj-ebpf Introduction

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.

Requirements

  • Java 25+ with Panama Foreign Function & Memory API
  • Linux kernel 5.8+ (for ring buffer support, earlier kernels have partial support)
  • Appropriate capabilities (CAP_BPF, CAP_SYS_ADMIN, or root)

Quick Start

(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)

Core Modules

High-Level API

ModuleDescription
clj-ebpf.coreMain entry point, initialization
clj-ebpf.mapsBPF map creation and manipulation
clj-ebpf.programsProgram loading and attachment
clj-ebpf.eventsRing buffer and perf event handling

DSL (Domain Specific Language)

ModuleDescription
clj-ebpf.dsl.coreUnified DSL API
clj-ebpf.dsl.aluArithmetic operations
clj-ebpf.dsl.memMemory operations
clj-ebpf.dsl.jumpControl flow
clj-ebpf.dsl.atomicAtomic operations
clj-ebpf.dsl.instructionsLow-level encoding

Program Types

ModuleDescription
clj-ebpf.xdpXDP program attachment
clj-ebpf.tcTraffic Control (TC) programs
clj-ebpf.cgroupCgroup programs
clj-ebpf.lsmLinux Security Modules
clj-ebpf.perfPerf event programs

Utilities

ModuleDescription
clj-ebpf.helpersBPF helper function metadata
clj-ebpf.errorsStructured error handling
clj-ebpf.archMulti-architecture support
clj-ebpf.constantsBPF constants and flags
clj-ebpf.utilsMemory utilities

Architecture Support

clj-ebpf supports multiple CPU architectures:

  • x86_64 (AMD64)
  • aarch64 (ARM64)
  • riscv64 (RISC-V 64-bit)
  • loongarch64 (LoongArch 64-bit)

The library automatically detects the architecture and uses appropriate syscall numbers.

Further Reading

Can you improve this documentation?Edit on GitHub

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close