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

AF-INETclj

source

AF-INET6clj

source

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-ANYclj

source

BPF-EXISTclj

source

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

BPF-NOEXISTclj

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

Delegates to clj-ebpf.net.bounds/build-bounds-check with r6/r7 convention.

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

Delegates to clj-ebpf.net.bounds/build-bounds-check with r6/r7 convention.
sourceraw docstring

build-copy-ipv6-addressclj

Generate instructions to copy a 16-byte IPv6 address from one stack location to another. Delegates to clj-ebpf.net.ipv6/build-copy-ipv6-address.

Generate instructions to copy a 16-byte IPv6 address from one stack location to another.
Delegates to clj-ebpf.net.ipv6/build-copy-ipv6-address.
sourceraw docstring

build-get-prandom-u32clj

Get a pseudo-random 32-bit number. Delegates to clj-ebpf.time/build-get-prandom-u32.

Get a pseudo-random 32-bit number.
Delegates to clj-ebpf.time/build-get-prandom-u32.
sourceraw docstring

build-ktime-get-nsclj

Get current time in nanoseconds. Delegates to clj-ebpf.time/build-ktime-get-ns.

Get current time in nanoseconds.
Delegates to clj-ebpf.time/build-ktime-get-ns.
sourceraw docstring

build-l3-csum-replaceclj

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

Generate incremental IP checksum update. Delegates to clj-ebpf.net.checksum/l3-csum-replace-4.

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

Generate incremental IP checksum update.
Delegates to clj-ebpf.net.checksum/l3-csum-replace-4.

skb-reg: Register containing skb/xdp_md pointer
csum-off: Offset of checksum field in packet
old-reg: Old value (in register)
new-reg: 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. Delegates to clj-ebpf.net.checksum/l4-csum-replace-4.

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

Generate incremental L4 (TCP/UDP) checksum update.
Delegates to clj-ebpf.net.checksum/l4-csum-replace-4.

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

build-load-ipv4-unifiedclj

Generate instructions to load a 4-byte IPv4 address into unified 16-byte format. Delegates to clj-ebpf.net.ipv6/build-load-ipv4-unified.

Generate instructions to load a 4-byte IPv4 address into unified 16-byte format.
Delegates to clj-ebpf.net.ipv6/build-load-ipv4-unified.
sourceraw docstring

build-load-ipv6-addressclj

Generate instructions to load a 16-byte IPv6 address from packet to stack. Delegates to clj-ebpf.net.ipv6/build-load-ipv6-address.

Generate instructions to load a 16-byte IPv6 address from packet to stack.
Delegates to clj-ebpf.net.ipv6/build-load-ipv6-address.
sourceraw docstring

build-load-ipv6-address-adjustedclj

Generate instructions to load a 16-byte IPv6 address with offset adjustment. Delegates to clj-ebpf.net.ipv6/build-load-ipv6-address-adjusted.

Generate instructions to load a 16-byte IPv6 address with offset adjustment.
Delegates to clj-ebpf.net.ipv6/build-load-ipv6-address-adjusted.
sourceraw docstring

build-load-ipv6-dstclj

Generate instructions to load IPv6 destination address from packet to stack. Delegates to clj-ebpf.net.ipv6/build-load-ipv6-dst.

Generate instructions to load IPv6 destination address from packet to stack.
Delegates to clj-ebpf.net.ipv6/build-load-ipv6-dst.
sourceraw docstring

build-load-ipv6-srcclj

Generate instructions to load IPv6 source address from packet to stack. Delegates to clj-ebpf.net.ipv6/build-load-ipv6-src.

Generate instructions to load IPv6 source address from packet to stack.
Delegates to clj-ebpf.net.ipv6/build-load-ipv6-src.
sourceraw docstring

build-map-deleteclj

Generate instructions for bpf_map_delete_elem. Delegates to clj-ebpf.maps.helpers/build-map-delete.

Generate instructions for bpf_map_delete_elem.
Delegates to clj-ebpf.maps.helpers/build-map-delete.
sourceraw docstring

build-map-lookupclj

Generate instructions for bpf_map_lookup_elem. Delegates to clj-ebpf.maps.helpers/build-map-lookup.

Generate instructions for bpf_map_lookup_elem.
Delegates to clj-ebpf.maps.helpers/build-map-lookup.
sourceraw docstring

build-map-lookup-or-initclj

Generate instructions for map lookup with initialization if not found. Delegates to clj-ebpf.maps.helpers/build-map-lookup-or-init.

Generate instructions for map lookup with initialization if not found.
Delegates to clj-ebpf.maps.helpers/build-map-lookup-or-init.
sourceraw docstring

build-map-updateclj

Generate instructions for bpf_map_update_elem. Delegates to clj-ebpf.maps.helpers/build-map-update.

Generate instructions for bpf_map_update_elem.
Delegates to clj-ebpf.maps.helpers/build-map-update.
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]. Delegates to clj-ebpf.time/build-random-mod.

Generate random number in range [0, 99].
Delegates to clj-ebpf.time/build-random-mod.
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

Discard ring buffer reservation. Delegates to clj-ebpf.ringbuf/build-ringbuf-discard.

Discard ring buffer reservation.
Delegates to clj-ebpf.ringbuf/build-ringbuf-discard.
sourceraw docstring

build-ringbuf-reserveclj

Reserve space in ring buffer. Delegates to clj-ebpf.ringbuf/build-ringbuf-reserve.

Reserve space in ring buffer.
Delegates to clj-ebpf.ringbuf/build-ringbuf-reserve.
sourceraw docstring

build-ringbuf-submitclj

Submit ring buffer entry. Delegates to clj-ebpf.ringbuf/build-ringbuf-submit.

Submit ring buffer entry.
Delegates to clj-ebpf.ringbuf/build-ringbuf-submit.
sourceraw docstring

build-store-ipv6-addressclj

Generate instructions to store a 16-byte IPv6 address from stack to packet. Delegates to clj-ebpf.net.ipv6/build-store-ipv6-address.

Generate instructions to store a 16-byte IPv6 address from stack to packet.
Delegates to clj-ebpf.net.ipv6/build-store-ipv6-address.
sourceraw docstring

build-zero-bytesclj

Generate instructions to zero a contiguous range of bytes on the stack. Delegates to clj-ebpf.memory/build-zero-bytes.

Generate instructions to zero a contiguous range of bytes on the stack.
Delegates to clj-ebpf.memory/build-zero-bytes.
sourceraw docstring

ETH-HLENclj

source

eth-is-ipv4clj

Check if packet is IPv4 and jump to label if true. Delegates to clj-ebpf.net.ethernet/is-ipv4.

Check if packet is IPv4 and jump to label if true.
Delegates to clj-ebpf.net.ethernet/is-ipv4.
sourceraw docstring

eth-is-ipv6clj

Check if packet is IPv6 and jump to label if true. Delegates to clj-ebpf.net.ethernet/is-ipv6.

Check if packet is IPv6 and jump to label if true.
Delegates to clj-ebpf.net.ethernet/is-ipv6.
sourceraw docstring

eth-is-not-ipv4clj

Check if packet is NOT IPv4 and jump to label if true. Delegates to clj-ebpf.net.ethernet/is-not-ipv4.

Check if packet is NOT IPv4 and jump to label if true.
Delegates to clj-ebpf.net.ethernet/is-not-ipv4.
sourceraw docstring

eth-load-ethertypeclj

Load ethertype from Ethernet header (network byte order). Delegates to clj-ebpf.net.ethernet/load-ethertype.

Load ethertype from Ethernet header (network byte order).
Delegates to clj-ebpf.net.ethernet/load-ethertype.
sourceraw docstring

ETH-P-IPclj

source

ETH-P-IP-BEclj

source

ETH-P-IPV6clj

source

ETH-P-IPV6-BEclj

source

eth-parse-ethernetclj

Parse Ethernet header with bounds check and load ethertype. Delegates to clj-ebpf.net.ethernet/parse-ethernet.

Parse Ethernet header with bounds check and load ethertype.
Delegates to clj-ebpf.net.ethernet/parse-ethernet.
sourceraw docstring

eth-swap-macsclj

Swap source and destination MAC addresses. Delegates to clj-ebpf.net.ethernet/swap-macs.

Swap source and destination MAC addresses.
Delegates to clj-ebpf.net.ethernet/swap-macs.
sourceraw docstring

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

ipv4-store-daddrclj

Store IPv4 destination address from register to packet. Delegates to clj-ebpf.net.ipv4/store-daddr.

Store IPv4 destination address from register to packet.
Delegates to clj-ebpf.net.ipv4/store-daddr.
sourceraw docstring

ipv4-store-saddrclj

Store IPv4 source address from register to packet. Delegates to clj-ebpf.net.ipv4/store-saddr.

Store IPv4 source address from register to packet.
Delegates to clj-ebpf.net.ipv4/store-saddr.
sourceraw docstring

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

SKB-OFF-DATAclj

source

SKB-OFF-DATA-ENDclj

source

SKB-OFF-LENclj

source

STACK-OFF-ADDR-FAMILYclj

source

STACK-OFF-CONNTRACK-KEYclj

source

STACK-OFF-DST-IPclj

source

STACK-OFF-DST-PORTclj

source

STACK-OFF-L4-OFFSETclj

source

STACK-OFF-PROTOCOLclj

source

STACK-OFF-SRC-IPclj

source

STACK-OFF-SRC-PORTclj

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

tcp-store-dportclj

Store TCP destination port from register to packet (network byte order). Delegates to clj-ebpf.net.tcp/store-dport.

Store TCP destination port from register to packet (network byte order).
Delegates to clj-ebpf.net.tcp/store-dport.
sourceraw docstring

tcp-store-sportclj

Store TCP source port from register to packet (network byte order). Delegates to clj-ebpf.net.tcp/store-sport.

Store TCP source port from register to packet (network byte order).
Delegates to clj-ebpf.net.tcp/store-sport.
sourceraw docstring

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

udp-store-dportclj

Store UDP destination port from register to packet (network byte order). Delegates to clj-ebpf.net.udp/store-dport.

Store UDP destination port from register to packet (network byte order).
Delegates to clj-ebpf.net.udp/store-dport.
sourceraw docstring

udp-store-sportclj

Store UDP source port from register to packet (network byte order). Delegates to clj-ebpf.net.udp/store-sport.

Store UDP source port from register to packet (network byte order).
Delegates to clj-ebpf.net.udp/store-sport.
sourceraw docstring

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