Liking cljdoc? Tell your friends :D
Clojure only.

lb.programs.common

Common eBPF program fragments and DSL utilities shared between XDP and TC programs.

Common eBPF program fragments and DSL utilities shared between XDP and TC programs.
raw docstring

add-immclj

(add-imm dst imm)

Add immediate to register.

Add immediate to register.
sourceraw docstring

add-regclj

(add-reg dst src)

Add register to register.

Add register to register.
sourceraw docstring

assemble-programclj

(assemble-program & fragments)

Assemble a program from instruction fragments. Returns BPF bytecode ready for loading.

Assemble a program from instruction fragments.
Returns BPF bytecode ready for loading.
sourceraw docstring

BPF-F-PSEUDO-HDRclj

source

BPF-F-RECOMPUTE-CSUMclj

source

BPF-FUNC-csum-diffclj

source

BPF-FUNC-get-prandom-u32clj

source

BPF-FUNC-ktime-get-nsclj

source

BPF-FUNC-l3-csum-replaceclj

source

BPF-FUNC-l4-csum-replaceclj

source

BPF-FUNC-map-delete-elemclj

source

BPF-FUNC-map-lookup-elemclj

source

BPF-FUNC-map-update-elemclj

source

BPF-FUNC-redirectclj

source

BPF-FUNC-redirect-mapclj

source

BPF-FUNC-ringbuf-discardclj

source

BPF-FUNC-ringbuf-reserveclj

source

BPF-FUNC-ringbuf-submitclj

source

BPF-FUNC-xdp-adjust-headclj

source

build-bounds-checkclj

(build-bounds-check offset size fail-offset)

Generate instructions to check if accessing [data + offset, data + offset + size) is within packet bounds. Jumps forward by fail-offset if out of bounds.

Assumes: r6 = data start, r7 = data end Uses: r8 as scratch

Generate instructions to check if accessing [data + offset, data + offset + size)
is within packet bounds. Jumps forward by fail-offset if out of bounds.

Assumes: r6 = data start, r7 = data end
Uses: r8 as scratch
sourceraw docstring

build-get-prandom-u32clj

(build-get-prandom-u32)

Get a pseudo-random 32-bit number. Result in r0.

Get a pseudo-random 32-bit number.
Result in r0.
sourceraw docstring

build-ktime-get-nsclj

(build-ktime-get-ns)

Get current time in nanoseconds. Result in r0.

Get current time in nanoseconds.
Result in r0.
sourceraw docstring

build-l3-csum-replaceclj

(build-l3-csum-replace skb-reg csum-off old-reg new-reg)

Generate incremental IP checksum update.

skb-reg: Register containing skb/xdp_md pointer csum-off: Offset of checksum field in packet old-val: Old value (in register) new-val: New value (in register)

Generate incremental IP checksum update.

skb-reg: Register containing skb/xdp_md pointer
csum-off: Offset of checksum field in packet
old-val: Old value (in register)
new-val: New value (in register)
sourceraw docstring

build-l4-csum-replaceclj

(build-l4-csum-replace skb-reg csum-off old-reg new-reg flags)

Generate incremental L4 (TCP/UDP) checksum update.

skb-reg: Register containing skb/xdp_md pointer csum-off: Offset of checksum field in packet old-val: Old value (in register) new-val: New value (in register) flags: BPF_F flags (use BPF-F-PSEUDO-HDR for IP address changes)

Generate incremental L4 (TCP/UDP) checksum update.

skb-reg: Register containing skb/xdp_md pointer
csum-off: Offset of checksum field in packet
old-val: Old value (in register)
new-val: New value (in register)
flags: BPF_F flags (use BPF-F-PSEUDO-HDR for IP address changes)
sourceraw docstring

build-map-lookupclj

(build-map-lookup map-fd key-stack-off)

Generate instructions for bpf_map_lookup_elem.

Args: map-fd: The map file descriptor (will be loaded as 64-bit immediate) key-stack-off: Stack offset where key is stored (negative)

Returns: instructions that leave result pointer in r0 (or NULL)

Generate instructions for bpf_map_lookup_elem.

Args:
  map-fd: The map file descriptor (will be loaded as 64-bit immediate)
  key-stack-off: Stack offset where key is stored (negative)

Returns: instructions that leave result pointer in r0 (or NULL)
sourceraw docstring

build-map-updateclj

(build-map-update map-fd key-stack-off value-stack-off flags)

Generate instructions for bpf_map_update_elem.

Args: map-fd: The map file descriptor key-stack-off: Stack offset where key is stored value-stack-off: Stack offset where value is stored flags: Update flags (0 = any, 1 = noexist, 2 = exist)

Generate instructions for bpf_map_update_elem.

Args:
  map-fd: The map file descriptor
  key-stack-off: Stack offset where key is stored
  value-stack-off: Stack offset where value is stored
  flags: Update flags (0 = any, 1 = noexist, 2 = exist)
sourceraw docstring

build-parse-ethclj

(build-parse-eth pass-offset)

Parse Ethernet header and check for IPv4.

Assumes: r6 = data, r7 = data_end After: jumps forward by pass-offset if not IPv4 Uses: r8 as scratch

Parse Ethernet header and check for IPv4.

Assumes: r6 = data, r7 = data_end
After: jumps forward by pass-offset if not IPv4
Uses: r8 as scratch
sourceraw docstring

build-parse-ipclj

(build-parse-ip pass-offset)

Parse IPv4 header, extract protocol and addresses.

Assumes: r6 = data, r7 = data_end, Ethernet header already validated Stores on stack: stack[-4] = protocol (1 byte as word) stack[-8] = src IP stack[-12] = dst IP stack[-16] = IP header length (bytes) Uses: r8, r9 as scratch

Parse IPv4 header, extract protocol and addresses.

Assumes: r6 = data, r7 = data_end, Ethernet header already validated
Stores on stack:
  stack[-4]  = protocol (1 byte as word)
  stack[-8]  = src IP
  stack[-12] = dst IP
  stack[-16] = IP header length (bytes)
Uses: r8, r9 as scratch
sourceraw docstring

build-parse-ipv6clj

(build-parse-ipv6 pass-offset)

Parse IPv6 header, extract next header (protocol) and addresses.

IPv6 has a fixed 40-byte header (no options in base header).

Assumes: r6 = data, r7 = data_end, Ethernet header already validated Stores on stack (unified format with 16-byte addresses): stack[-4] = next header (protocol, 1 byte as word) stack[-20] = src IP (16 bytes, at stack[-20..-5]) stack[-36] = dst IP (16 bytes, at stack[-36..-21]) stack[-40] = header length (always 40 for base IPv6) Uses: r8, r9 as scratch

Parse IPv6 header, extract next header (protocol) and addresses.

IPv6 has a fixed 40-byte header (no options in base header).

Assumes: r6 = data, r7 = data_end, Ethernet header already validated
Stores on stack (unified format with 16-byte addresses):
  stack[-4]   = next header (protocol, 1 byte as word)
  stack[-20]  = src IP (16 bytes, at stack[-20..-5])
  stack[-36]  = dst IP (16 bytes, at stack[-36..-21])
  stack[-40]  = header length (always 40 for base IPv6)
Uses: r8, r9 as scratch
sourceraw docstring

build-parse-l4clj

(build-parse-l4 pass-offset)

Parse TCP/UDP header to extract ports.

Assumes: stack[-16] = IP header length, r6 = data, r7 = data_end Stores on stack: stack[-20] = src port stack[-24] = dst port Uses: r8, r9

Parse TCP/UDP header to extract ports.

Assumes: stack[-16] = IP header length, r6 = data, r7 = data_end
Stores on stack:
  stack[-20] = src port
  stack[-24] = dst port
Uses: r8, r9
sourceraw docstring

build-parse-l4-ipv6clj

(build-parse-l4-ipv6 pass-offset)

Parse TCP/UDP header to extract ports for IPv6.

IPv6 has fixed 40-byte header, so L4 is always at ETH_HLEN + 40.

Assumes: r6 = data, r7 = data_end, IPv6 header validated Stores on stack: stack[-44] = src port stack[-48] = dst port Uses: r8, r9

Parse TCP/UDP header to extract ports for IPv6.

IPv6 has fixed 40-byte header, so L4 is always at ETH_HLEN + 40.

Assumes: r6 = data, r7 = data_end, IPv6 header validated
Stores on stack:
  stack[-44] = src port
  stack[-48] = dst port
Uses: r8, r9
sourceraw docstring

build-random-mod-100clj

(build-random-mod-100)

Generate random number in range [0, 99]. Result in r0. Uses: r0, r1 as scratch

Generate random number in range [0, 99].
Result in r0.
Uses: r0, r1 as scratch
sourceraw docstring

build-rate-limit-checkclj

(build-rate-limit-check config-map-fd
                        config-index
                        bucket-map-fd
                        key-stack-off
                        scratch-stack-off
                        skip-label
                        drop-label)

Generate BPF instructions for token bucket rate limit check.

This implements a token bucket algorithm:

  1. Load config from config-map at config-index
  2. If rate == 0, skip (rate limiting disabled)
  3. Load/create bucket from bucket-map using key at key-stack-off
  4. Calculate elapsed time since last update
  5. Add tokens: new_tokens = old_tokens + elapsed_ns * rate / 1e9
  6. Cap at burst
  7. If tokens >= 1 (1000 scaled), consume and continue
  8. Else jump to drop-label

Stack usage (relative to current-stack-off): offset 0-15: rate limit config (rate, burst) offset 16-31: bucket state (tokens, last_update)

Parameters: config-map-fd: FD for rate_limit_config array map config-index: 0 for source, 1 for backend bucket-map-fd: FD for rate_limit_src or rate_limit_backend LRU map key-stack-off: Stack offset where lookup key is stored scratch-stack-off: Stack offset for scratch space (needs 32 bytes) skip-label: Label to jump to if rate limiting disabled/passed drop-label: Label to jump to if rate limited

Generate BPF instructions for token bucket rate limit check.

This implements a token bucket algorithm:
1. Load config from config-map at config-index
2. If rate == 0, skip (rate limiting disabled)
3. Load/create bucket from bucket-map using key at key-stack-off
4. Calculate elapsed time since last update
5. Add tokens: new_tokens = old_tokens + elapsed_ns * rate / 1e9
6. Cap at burst
7. If tokens >= 1 (1000 scaled), consume and continue
8. Else jump to drop-label

Stack usage (relative to current-stack-off):
offset 0-15: rate limit config (rate, burst)
offset 16-31: bucket state (tokens, last_update)

Parameters:
config-map-fd: FD for rate_limit_config array map
config-index: 0 for source, 1 for backend
bucket-map-fd: FD for rate_limit_src or rate_limit_backend LRU map
key-stack-off: Stack offset where lookup key is stored
scratch-stack-off: Stack offset for scratch space (needs 32 bytes)
skip-label: Label to jump to if rate limiting disabled/passed
drop-label: Label to jump to if rate limited
sourceraw docstring

build-ringbuf-discardclj

(build-ringbuf-discard ptr-reg)

Discard ring buffer reservation.

ptr-reg: Register containing pointer from reserve

Discard ring buffer reservation.

ptr-reg: Register containing pointer from reserve
sourceraw docstring

build-ringbuf-reserveclj

(build-ringbuf-reserve ringbuf-fd size)

Reserve space in ring buffer.

ringbuf-fd: Ring buffer map FD size: Size to reserve

Returns ptr in r0 (or NULL on failure)

Reserve space in ring buffer.

ringbuf-fd: Ring buffer map FD
size: Size to reserve

Returns ptr in r0 (or NULL on failure)
sourceraw docstring

build-ringbuf-submitclj

(build-ringbuf-submit ptr-reg)

Submit ring buffer entry.

ptr-reg: Register containing pointer from reserve

Submit ring buffer entry.

ptr-reg: Register containing pointer from reserve
sourceraw docstring

ETH-HLENclj

source

ETH-P-IPclj

source

ETH-P-IP-BEclj

source

ETH-P-IPV6clj

source

ETH-P-IPV6-BEclj

source

flatten-instructionsclj

(flatten-instructions & instruction-groups)

Flatten nested instruction vectors. Returns a flat vector of instructions.

Flatten nested instruction vectors.
Returns a flat vector of instructions.
sourceraw docstring

FNV1A-64-OFFSET-BASIS-HIclj

source

FNV1A-64-OFFSET-BASIS-LOclj

source

FNV1A-64-PRIME-HIclj

source

FNV1A-64-PRIME-LOclj

source

HTTPS-PORT-BEclj

source

IP-HLEN-MINclj

source

IPPROTO-ICMPclj

source

IPPROTO-ICMPV6clj

source

IPPROTO-TCPclj

source

IPPROTO-UDPclj

source

IPV6-HLENclj

source

IPV6-OFF-DSTclj

source

IPV6-OFF-HOP-LIMITclj

source

IPV6-OFF-NEXT-HEADERclj

source

IPV6-OFF-SRCclj

source

ldx-bclj

(ldx-b dst src off)

Load byte from memory.

Load byte from memory.
sourceraw docstring

ldx-dwclj

(ldx-dw dst src off)

Load double-word (8 bytes) from memory.

Load double-word (8 bytes) from memory.
sourceraw docstring

ldx-hclj

(ldx-h dst src off)

Load half-word (2 bytes) from memory.

Load half-word (2 bytes) from memory.
sourceraw docstring

ldx-wclj

(ldx-w dst src off)

Load word (4 bytes) from memory.

Load word (4 bytes) from memory.
sourceraw docstring

map-fdclj

(map-fd m)

Get the raw file descriptor for a map. This is needed when building eBPF programs that reference maps.

Get the raw file descriptor for a map.
This is needed when building eBPF programs that reference maps.
sourceraw docstring

MAX-SNI-LENGTHclj

source

MAX-TLS-EXTENSIONSclj

source

mov-immclj

(mov-imm dst imm)

Move immediate value to register.

Move immediate value to register.
sourceraw docstring

mov-regclj

(mov-reg dst src)

Move register to register.

Move register to register.
sourceraw docstring

RATE-LIMIT-CONFIG-BACKENDclj

source

RATE-LIMIT-CONFIG-SRCclj

source

stx-bclj

(stx-b dst src off)

Store byte to memory. Signature: *(dst + off) = src

Store byte to memory.
Signature: *(dst + off) = src
sourceraw docstring

stx-dwclj

(stx-dw dst src off)

Store double-word to memory. Signature: *(dst + off) = src

Store double-word to memory.
Signature: *(dst + off) = src
sourceraw docstring

stx-hclj

(stx-h dst src off)

Store half-word to memory. Signature: *(dst + off) = src

Store half-word to memory.
Signature: *(dst + off) = src
sourceraw docstring

stx-wclj

(stx-w dst src off)

Store word to memory. Signature: *(dst + off) = src

Store word to memory.
Signature: *(dst + off) = src
sourceraw docstring

sub-immclj

(sub-imm dst imm)

Subtract immediate from register.

Subtract immediate from register.
sourceraw docstring

sub-regclj

(sub-reg dst src)

Subtract register from register.

Subtract register from register.
sourceraw docstring

TC-ACT-OKclj

source

TC-ACT-REDIRECTclj

source

TC-ACT-SHOTclj

source

tc-drop-allclj

(tc-drop-all)

Simple TC program that drops all packets.

Simple TC program that drops all packets.
sourceraw docstring

tc-pass-allclj

(tc-pass-all)

Simple TC program that passes all packets.

Simple TC program that passes all packets.
sourceraw docstring

TCP-HLEN-MINclj

source

TLS-CONTENT-TYPE-HANDSHAKEclj

source

TLS-EXT-SNIclj

source

TLS-HANDSHAKE-CLIENT-HELLOclj

source

TLS-HANDSHAKE-HEADER-SIZEclj

source

TLS-HANDSHAKE-LENGTH-OFFclj

source

TLS-HANDSHAKE-TYPE-OFFclj

source

TLS-RECORD-CONTENT-TYPE-OFFclj

source

TLS-RECORD-HEADER-SIZEclj

source

TLS-RECORD-LENGTH-OFFclj

source

TLS-RECORD-VERSION-OFFclj

source

TLS-SNI-NAME-TYPE-HOSTNAMEclj

source

TOKEN-SCALEclj

source

UDP-HLENclj

source

XDP-ABORTEDclj

source

XDP-DROPclj

source

xdp-drop-allclj

(xdp-drop-all)

Simple XDP program that drops all packets.

Simple XDP program that drops all packets.
sourceraw docstring

XDP-PASSclj

source

xdp-pass-allclj

(xdp-pass-all)

Simple XDP program that passes all packets. Useful for testing XDP attachment.

Simple XDP program that passes all packets.
Useful for testing XDP attachment.
sourceraw docstring

XDP-REDIRECTclj

source

XDP-TXclj

source

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