Liking cljdoc? Tell your friends :D

clj-ebpf.arch

Architecture detection and platform-specific constants.

Provides runtime detection of CPU architecture and appropriate syscall numbers, libc paths, and other platform-specific values.

Architecture detection and platform-specific constants.

Provides runtime detection of CPU architecture and appropriate
syscall numbers, libc paths, and other platform-specific values.
raw docstring

clj-ebpf.core

Main API for clj-ebpf - eBPF programming in Clojure

Main API for clj-ebpf - eBPF programming in Clojure
raw docstring

clj-ebpf.dsl

Idiomatic Clojure DSL for BPF programming

Idiomatic Clojure DSL for BPF programming
raw docstring

clj-ebpf.dsl.alu

ALU (Arithmetic Logic Unit) operations for BPF programs.

Provides 32-bit and 64-bit arithmetic operations:

  • Arithmetic: add, sub, mul, div, mod, neg
  • Bitwise: and, or, xor, lsh, rsh, arsh
  • Data movement: mov
  • Endianness conversion: end-to-be, end-to-le
ALU (Arithmetic Logic Unit) operations for BPF programs.

Provides 32-bit and 64-bit arithmetic operations:
- Arithmetic: add, sub, mul, div, mod, neg
- Bitwise: and, or, xor, lsh, rsh, arsh
- Data movement: mov
- Endianness conversion: end-to-be, end-to-le
raw docstring

clj-ebpf.dsl.atomic

Atomic memory operations for BPF programs.

Provides thread-safe operations for concurrent access to shared memory, essential for implementing lock-free counters, statistics, and data structures.

Available operations:

  • atomic-add : *dst += src
  • atomic-or : *dst |= src
  • atomic-and : *dst &= src
  • atomic-xor : *dst ^= src
  • atomic-xchg : src = xchg(*dst, src)
  • atomic-cmpxchg: r0 = cmpxchg(*dst, r0, src)

Fetch variants return the original value:

  • atomic-fetch-add, atomic-fetch-or, atomic-fetch-and, atomic-fetch-xor

All operations support 32-bit (:w) and 64-bit (:dw) sizes.

Example:

;; Increment counter atomically
(atomic-add :dw :r1 :r2 0)  ; *r1 += r2

;; Fetch and add (returns old value in src register)
(atomic-fetch-add :dw :r1 :r2 0)  ; r2 = fetch_add(*r1, r2)
Atomic memory operations for BPF programs.

Provides thread-safe operations for concurrent access to shared memory,
essential for implementing lock-free counters, statistics, and data structures.

Available operations:
- atomic-add    : *dst += src
- atomic-or     : *dst |= src
- atomic-and    : *dst &= src
- atomic-xor    : *dst ^= src
- atomic-xchg   : src = xchg(*dst, src)
- atomic-cmpxchg: r0 = cmpxchg(*dst, r0, src)

Fetch variants return the original value:
- atomic-fetch-add, atomic-fetch-or, atomic-fetch-and, atomic-fetch-xor

All operations support 32-bit (:w) and 64-bit (:dw) sizes.

Example:
```clojure
;; Increment counter atomically
(atomic-add :dw :r1 :r2 0)  ; *r1 += r2

;; Fetch and add (returns old value in src register)
(atomic-fetch-add :dw :r1 :r2 0)  ; r2 = fetch_add(*r1, r2)
```
raw docstring

clj-ebpf.dsl.core

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:

  • 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
  • clj-ebpf.dsl.structs - Event structure definitions
  • clj-ebpf.dsl.kprobe - Kprobe program helpers
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
- clj-ebpf.dsl.structs - Event structure definitions
- clj-ebpf.dsl.kprobe - Kprobe program helpers
raw docstring

clj-ebpf.dsl.instructions

Low-level BPF instruction encoding.

This namespace provides the fundamental BPF instruction encoding primitives. It defines:

  • Instruction format constants
  • Opcode construction
  • Single instruction encoding
  • Register definitions

BPF instructions are 64-bit: |immediate:32|offset:16|src_reg:4|dst_reg:4|opcode:8|

Low-level BPF instruction encoding.

This namespace provides the fundamental BPF instruction encoding primitives.
It defines:
- Instruction format constants
- Opcode construction
- Single instruction encoding
- Register definitions

BPF instructions are 64-bit:
|immediate:32|offset:16|src_reg:4|dst_reg:4|opcode:8|
raw docstring

clj-ebpf.dsl.jump

Jump and control flow operations for BPF programs.

Provides:

  • Conditional jumps (jeq, jne, jgt, jge, etc.)
  • Unconditional jumps (ja)
  • Function calls (call, call-helper)
  • Program exit (exit)
Jump and control flow operations for BPF programs.

Provides:
- Conditional jumps (jeq, jne, jgt, jge, etc.)
- Unconditional jumps (ja)
- Function calls (call, call-helper)
- Program exit (exit)
raw docstring

clj-ebpf.dsl.kprobe

High-level kprobe definition macros for BPF programs.

Provides the defkprobe macro for defining kprobe handlers with automatic argument extraction and common setup patterns.

Example: (defkprobe tcp-connect :function "tcp_v4_connect" :args [sk] ; First function argument (concat (helper-get-current-pid-tgid) [(mov-reg :r6 :r0)] ; Save pid_tgid ;; ... rest of program [(exit-insn)]))

High-level kprobe definition macros for BPF programs.

Provides the defkprobe macro for defining kprobe handlers with
automatic argument extraction and common setup patterns.

Example:
  (defkprobe tcp-connect
    :function "tcp_v4_connect"
    :args [sk]  ; First function argument
    (concat
      (helper-get-current-pid-tgid)
      [(mov-reg :r6 :r0)]  ; Save pid_tgid
      ;; ... rest of program
      [(exit-insn)]))
raw docstring

clj-ebpf.dsl.mem

Memory operations for BPF programs.

Provides:

  • Load operations (ldx, ld)
  • Store operations (stx, st)
  • Atomic operations (atomic-add, atomic-xchg, etc.)
  • 64-bit immediate loads (lddw)
Memory operations for BPF programs.

Provides:
- Load operations (ldx, ld)
- Store operations (stx, st)
- Atomic operations (atomic-add, atomic-xchg, etc.)
- 64-bit immediate loads (lddw)
raw docstring

clj-ebpf.dsl.structs

Event structure definition DSL for BPF programs.

Provides macros and functions for defining event structures that can be used with ring buffers. The defevent macro creates structure definitions with automatic offset calculation and store function generation.

Example: (defevent ConnectionEvent [:timestamp :u64] [:pid :u32] [:saddr :u32] [:daddr :u32] [:sport :u16] [:dport :u16] [:protocol :u8] [:direction :u8] [:padding :u8 2] [:comm :char 16])

;; Get size: (event-size ConnectionEvent) => 44 ;; Get offset: (event-field-offset ConnectionEvent :pid) => 8 ;; Generate store: (store-event-field :r6 ConnectionEvent :pid :r7)

Event structure definition DSL for BPF programs.

Provides macros and functions for defining event structures that can
be used with ring buffers. The defevent macro creates structure definitions
with automatic offset calculation and store function generation.

Example:
  (defevent ConnectionEvent
    [:timestamp :u64]
    [:pid :u32]
    [:saddr :u32]
    [:daddr :u32]
    [:sport :u16]
    [:dport :u16]
    [:protocol :u8]
    [:direction :u8]
    [:padding :u8 2]
    [:comm :char 16])

  ;; Get size: (event-size ConnectionEvent) => 44
  ;; Get offset: (event-field-offset ConnectionEvent :pid) => 8
  ;; Generate store: (store-event-field :r6 ConnectionEvent :pid :r7)
raw docstring

clj-ebpf.elf

ELF (Executable and Linkable Format) parser for BPF programs

ELF (Executable and Linkable Format) parser for BPF programs
raw docstring

clj-ebpf.errors

Structured error handling for clj-ebpf.

Provides:

  • Typed exception hierarchy for BPF operations
  • Automatic retry for transient errors
  • Rich error context and diagnostics
Structured error handling for clj-ebpf.

Provides:
- Typed exception hierarchy for BPF operations
- Automatic retry for transient errors
- Rich error context and diagnostics
raw docstring

clj-ebpf.examples

Comprehensive examples demonstrating the clj-ebpf DSL for BPF programming.

These examples showcase various BPF program types and common patterns:

  • XDP (eXpress Data Path) programs for high-performance packet filtering
  • TC (Traffic Control) programs for packet classification
  • Packet parsing (Ethernet, IP, TCP/UDP headers)
  • BPF map operations (lookup, update, delete)
  • Tracing and debugging with helper functions
  • Statistics and counters

Each example is documented with its purpose, expected behavior, and the BPF concepts it demonstrates.

Comprehensive examples demonstrating the clj-ebpf DSL for BPF programming.

These examples showcase various BPF program types and common patterns:
- XDP (eXpress Data Path) programs for high-performance packet filtering
- TC (Traffic Control) programs for packet classification
- Packet parsing (Ethernet, IP, TCP/UDP headers)
- BPF map operations (lookup, update, delete)
- Tracing and debugging with helper functions
- Statistics and counters

Each example is documented with its purpose, expected behavior, and
the BPF concepts it demonstrates.
raw docstring

clj-ebpf.helpers

BPF helper function metadata and utilities.

Helper metadata is loaded from resources/bpf-helpers.edn, which allows easy extension and customization without code changes.

Usage:

  • (get-helper-info :map-lookup-elem) - Get metadata for a helper
  • (get-helper-id :ktime-get-ns) - Get helper function ID
  • (helpers-by-category :network) - Get all network helpers
  • (available-helpers :xdp "5.8") - Get helpers for program type and kernel
BPF helper function metadata and utilities.

Helper metadata is loaded from resources/bpf-helpers.edn, which allows
easy extension and customization without code changes.

Usage:
- (get-helper-info :map-lookup-elem) - Get metadata for a helper
- (get-helper-id :ktime-get-ns) - Get helper function ID
- (helpers-by-category :network) - Get all network helpers
- (available-helpers :xdp "5.8") - Get helpers for program type and kernel
raw docstring

clj-ebpf.internal.memory

Low-level memory management using Panama FFI.

This namespace provides the foundational memory primitives used throughout clj-ebpf. It wraps Java's Foreign Function & Memory API (Panama) to provide a Clojure-friendly interface for:

  • Memory allocation and deallocation
  • Reading and writing primitive types
  • Memory segment manipulation
  • Buffer management for BPF operations

INTERNAL: This namespace is for internal use only. Public APIs should use clj-ebpf.utils for memory operations.

Low-level memory management using Panama FFI.

This namespace provides the foundational memory primitives used throughout
clj-ebpf. It wraps Java's Foreign Function & Memory API (Panama) to provide
a Clojure-friendly interface for:

- Memory allocation and deallocation
- Reading and writing primitive types
- Memory segment manipulation
- Buffer management for BPF operations

INTERNAL: This namespace is for internal use only. Public APIs should use
clj-ebpf.utils for memory operations.
raw docstring

clj-ebpf.refs

Idiomatic Clojure references for BPF data structures.

This namespace provides Clojure reference types that implement standard protocols (IDeref, IBlockingDeref, IAtom, ITransientCollection), enabling natural use of @, deref, reset!, swap!, and conj! with BPF maps.

== Read-Only References ==

  1. RingBufRef - Blocking reads from ring buffers @ref ; blocks until event available (deref ref 1000 nil) ; 1s timeout

  2. QueueRef/StackRef - Blocking pops from queue/stack maps @ref ; blocks until item available

  3. MapWatcher - Watch for a key to appear/change @ref ; blocks until key exists

== Writable References ==

  1. MapEntryRef - Atom-like access to map entries @ref ; read value (reset! ref val) ; write value (swap! ref inc) ; read-modify-write

  2. QueueWriter/StackWriter - Push to queues/stacks (conj! ref val) ; push value @ref ; peek (non-blocking)

  3. QueueChannel/StackChannel - Bidirectional access (conj! ref val) ; push @ref ; blocking pop

Idiomatic Clojure references for BPF data structures.

This namespace provides Clojure reference types that implement standard
protocols (IDeref, IBlockingDeref, IAtom, ITransientCollection), enabling
natural use of @, deref, reset!, swap!, and conj! with BPF maps.

== Read-Only References ==

1. RingBufRef - Blocking reads from ring buffers
   @ref                    ; blocks until event available
   (deref ref 1000 nil)    ; 1s timeout

2. QueueRef/StackRef - Blocking pops from queue/stack maps
   @ref                    ; blocks until item available

3. MapWatcher - Watch for a key to appear/change
   @ref                    ; blocks until key exists

== Writable References ==

4. MapEntryRef - Atom-like access to map entries
   @ref                    ; read value
   (reset! ref val)        ; write value
   (swap! ref inc)         ; read-modify-write

5. QueueWriter/StackWriter - Push to queues/stacks
   (conj! ref val)         ; push value
   @ref                    ; peek (non-blocking)

6. QueueChannel/StackChannel - Bidirectional access
   (conj! ref val)         ; push
   @ref                    ; blocking pop
raw docstring

clj-ebpf.relocate

CO-RE (Compile Once - Run Everywhere) relocation support.

This namespace provides functionality for BPF CO-RE relocations, enabling BPF programs to be portable across different kernel versions by using BTF information to relocate field accesses and type information at load time.

CO-RE relocations allow BPF programs to:

  • Access struct fields regardless of their offset in different kernel versions
  • Check for field/type/enum existence at load time
  • Get accurate field sizes and types
  • Handle bitfield operations correctly
  • Support both local and target BTF type IDs

Key concepts:

  • Field relocations: Adjust field offsets, sizes, existence
  • Type relocations: Check type existence, size, matches
  • Enum relocations: Get enum values, check existence
  • BTF-based resolution: Use kernel BTF to resolve relocations
CO-RE (Compile Once - Run Everywhere) relocation support.

This namespace provides functionality for BPF CO-RE relocations, enabling
BPF programs to be portable across different kernel versions by using BTF
information to relocate field accesses and type information at load time.

CO-RE relocations allow BPF programs to:
- Access struct fields regardless of their offset in different kernel versions
- Check for field/type/enum existence at load time
- Get accurate field sizes and types
- Handle bitfield operations correctly
- Support both local and target BTF type IDs

Key concepts:
- Field relocations: Adjust field offsets, sizes, existence
- Type relocations: Check type existence, size, matches
- Enum relocations: Get enum values, check existence
- BTF-based resolution: Use kernel BTF to resolve relocations
raw docstring

clj-ebpf.xdp

XDP (eXpress Data Path) support for high-performance packet processing

XDP (eXpress Data Path) support for high-performance packet processing
raw docstring

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