Liking cljdoc? Tell your friends :D

lb.util

Utility functions for IP address conversion, CIDR parsing, and binary encoding.

Utility functions for IP address conversion, CIDR parsing, and binary encoding.
raw docstring

bytes->ipclj

(bytes->ip b)

Convert 4-byte array to IP u32.

Convert 4-byte array to IP u32.
sourceraw docstring

cidr->stringclj

(cidr->string {:keys [ip prefix-len]})

Convert {:ip <u32> :prefix-len <int>} back to CIDR string.

Convert {:ip <u32> :prefix-len <int>} back to CIDR string.
sourceraw docstring

decode-conntrack-keyclj

(decode-conntrack-key b)

Decode connection tracking key from byte array.

Decode connection tracking key from byte array.
sourceraw docstring

decode-conntrack-valueclj

(decode-conntrack-value b)

Decode connection tracking value from byte array (64 bytes).

Decode connection tracking value from byte array (64 bytes).
sourceraw docstring

decode-listen-keyclj

(decode-listen-key b)

Decode listen map key from byte array.

Decode listen map key from byte array.
sourceraw docstring

decode-lpm-keyclj

(decode-lpm-key b)

Decode LPM trie key from byte array.

Decode LPM trie key from byte array.
sourceraw docstring

decode-route-valueclj

(decode-route-value b)

Decode route value from byte array.

Decode route value from byte array.
sourceraw docstring

decode-sni-keyclj

(decode-sni-key b)

Decode SNI map key from byte array.

Decode SNI map key from byte array.
sourceraw docstring

decode-stats-eventclj

(decode-stats-event b)

Decode stats event from ring buffer.

Decode stats event from ring buffer.
sourceraw docstring

decode-weighted-route-valueclj

(decode-weighted-route-value b)

Decode weighted route value from byte array (72 bytes). Returns {:target-count :flags :targets} where targets is a vector of {:ip :port :cumulative-weight} maps.

Decode weighted route value from byte array (72 bytes).
Returns {:target-count :flags :targets} where targets is a vector of
{:ip :port :cumulative-weight} maps.
sourceraw docstring

encode-conntrack-keyclj

(encode-conntrack-key {:keys [src-ip dst-ip src-port dst-port protocol]})

Encode connection tracking 5-tuple key. {src_ip (4) + dst_ip (4) + src_port (2) + dst_port (2) + protocol (1) + padding (3)} Total: 16 bytes (aligned). XDP stores packet values (network byte order) directly, so we use big-endian to match packet byte layout.

Encode connection tracking 5-tuple key.
{src_ip (4) + dst_ip (4) + src_port (2) + dst_port (2) + protocol (1) + padding (3)}
Total: 16 bytes (aligned).
XDP stores packet values (network byte order) directly, so we use big-endian
to match packet byte layout.
sourceraw docstring

encode-conntrack-valueclj

(encode-conntrack-value {:keys [orig-dst-ip orig-dst-port nat-dst-ip
                                nat-dst-port created-ns last-seen packets-fwd
                                packets-rev bytes-fwd bytes-rev]})

Encode connection tracking value. {orig_dst_ip (4) + orig_dst_port (2) + padding (2) + nat_dst_ip (4) + nat_dst_port (2) + padding (2) + created_ns (8) + last_seen_ns (8) + packets_fwd (8) + packets_rev (8) + bytes_fwd (8) + bytes_rev (8)} Total: 64 bytes. IPs and ports in network byte order (from packet), counters in native order.

Encode connection tracking value.
{orig_dst_ip (4) + orig_dst_port (2) + padding (2) + nat_dst_ip (4) + nat_dst_port (2) + padding (2) +
 created_ns (8) + last_seen_ns (8) + packets_fwd (8) + packets_rev (8) + bytes_fwd (8) + bytes_rev (8)}
Total: 64 bytes.
IPs and ports in network byte order (from packet), counters in native order.
sourceraw docstring

encode-listen-keyclj

(encode-listen-key ifindex port)

Encode listen map key: {ifindex (4 bytes) + port (2 bytes) + padding (2 bytes)}. Total: 8 bytes (aligned). Uses native byte order for ifindex, but BIG_ENDIAN for port to match raw packet bytes that XDP loads with ldx :h.

Encode listen map key: {ifindex (4 bytes) + port (2 bytes) + padding (2 bytes)}.
Total: 8 bytes (aligned).
Uses native byte order for ifindex, but BIG_ENDIAN for port to match
raw packet bytes that XDP loads with ldx :h.
sourceraw docstring

encode-lpm-keyclj

(encode-lpm-key prefix-len ip-u32)

Encode LPM trie key: {prefix_len (4 bytes) + ip (4 bytes)}. Total: 8 bytes.

Encode LPM trie key: {prefix_len (4 bytes) + ip (4 bytes)}.
Total: 8 bytes.
sourceraw docstring

encode-route-valueclj

(encode-route-value target-ip target-port flags)

Encode route value: {target_ip (4 bytes) + target_port (2 bytes) + flags (2 bytes)}. Total: 8 bytes. IP and port are stored in NETWORK byte order (big-endian) because XDP writes them directly to packet headers which are in network byte order. Flags remain in native order since they're only used internally.

Encode route value: {target_ip (4 bytes) + target_port (2 bytes) + flags (2 bytes)}.
Total: 8 bytes.
IP and port are stored in NETWORK byte order (big-endian) because XDP writes
them directly to packet headers which are in network byte order.
Flags remain in native order since they're only used internally.
sourceraw docstring

encode-sni-keyclj

(encode-sni-key hostname-hash)

Encode SNI map key from hostname hash. Key: hostname_hash (8 bytes) = 8 bytes total. Uses native byte order for efficient lookup.

Encode SNI map key from hostname hash.
Key: hostname_hash (8 bytes) = 8 bytes total.
Uses native byte order for efficient lookup.
sourceraw docstring

encode-stats-eventclj

(encode-stats-event {:keys [event-type timestamp src-ip dst-ip src-port dst-port
                            target-ip target-port packets-fwd bytes-fwd
                            packets-rev bytes-rev]})

Encode a stats event for ring buffer. {event_type (1) + padding (3) + timestamp (8) + src_ip (4) + dst_ip (4) + src_port (2) + dst_port (2) + target_ip (4) + target_port (2) + padding (2) + packets_fwd (8) + bytes_fwd (8) + packets_rev (8) + bytes_rev (8)} Total: 64 bytes.

Encode a stats event for ring buffer.
{event_type (1) + padding (3) + timestamp (8) + src_ip (4) + dst_ip (4) +
 src_port (2) + dst_port (2) + target_ip (4) + target_port (2) + padding (2) +
 packets_fwd (8) + bytes_fwd (8) + packets_rev (8) + bytes_rev (8)}
Total: 64 bytes.
sourceraw docstring

encode-weighted-route-valueclj

(encode-weighted-route-value target-group)
(encode-weighted-route-value target-group flags)

Encode weighted route value for BPF map. target-group is a TargetGroup record with :targets and :cumulative-weights. flags is optional (default 0).

Format (max 72 bytes):

  • Header (8 bytes): target_count(1) + reserved(3) + flags(2) + reserved(2)
  • Per target (8 bytes each): ip(4) + port(2) + cumulative_weight(2)

IP and port are stored in network byte order for direct packet writes.

Encode weighted route value for BPF map.
target-group is a TargetGroup record with :targets and :cumulative-weights.
flags is optional (default 0).

Format (max 72 bytes):
- Header (8 bytes): target_count(1) + reserved(3) + flags(2) + reserved(2)
- Per target (8 bytes each): ip(4) + port(2) + cumulative_weight(2)

IP and port are stored in network byte order for direct packet writes.
sourceraw docstring

ETH-HLENclj

source

ETH-P-ARPclj

source

ETH-P-IPclj

source

ETH-P-IPV6clj

source

FLAG-SESSION-PERSISTENCEclj

source

fnv1a-64clj

(fnv1a-64 data)

Compute FNV-1a 64-bit hash of a byte array. This is a fast, non-cryptographic hash suitable for hash table lookups.

Compute FNV-1a 64-bit hash of a byte array.
This is a fast, non-cryptographic hash suitable for hash table lookups.
sourceraw docstring

FNV1A-64-OFFSET-BASISclj

source

FNV1A-64-PRIMEclj

source

get-interface-indexclj

(get-interface-index iface-name)

Get interface index by name using /sys/class/net. Returns nil if interface not found.

Get interface index by name using /sys/class/net.
Returns nil if interface not found.
sourceraw docstring

hostname->hashclj

(hostname->hash hostname)

Hash a hostname for SNI map lookup using FNV-1a 64-bit. Hostname is lowercased before hashing for case-insensitive matching.

Hash a hostname for SNI map lookup using FNV-1a 64-bit.
Hostname is lowercased before hashing for case-insensitive matching.
sourceraw docstring

ip->bytesclj

(ip->bytes ip-u32)

Convert IP u32 to byte array (4 bytes, big-endian).

Convert IP u32 to byte array (4 bytes, big-endian).
sourceraw docstring

IP-HLEN-MINclj

source

ip-in-cidr?clj

(ip-in-cidr? ip-u32 {:keys [ip prefix-len]})

Check if an IP address (u32) falls within a CIDR range.

Check if an IP address (u32) falls within a CIDR range.
sourceraw docstring

ip-string->u32clj

(ip-string->u32 ip-str)

Convert dotted-decimal IP string to network byte order u32. Example: "192.168.1.1" => 0xC0A80101 (3232235777)

Convert dotted-decimal IP string to network byte order u32.
Example: "192.168.1.1" => 0xC0A80101 (3232235777)
sourceraw docstring

IPPROTO-ICMPclj

source

IPPROTO-TCPclj

source

IPPROTO-UDPclj

source

is-ip-string?clj

(is-ip-string? s)

Check if a string looks like an IPv4 address.

Check if a string looks like an IPv4 address.
sourceraw docstring

list-interfacesclj

(list-interfaces)

List all network interface names.

List all network interface names.
sourceraw docstring

parse-cidrclj

(parse-cidr cidr-str)

Parse CIDR notation string to {:ip <u32> :prefix-len <int>}. Supports both CIDR (e.g., "192.168.1.0/24") and single IP (e.g., "192.168.1.1"). Single IPs are treated as /32.

Parse CIDR notation string to {:ip <u32> :prefix-len <int>}.
Supports both CIDR (e.g., "192.168.1.0/24") and single IP (e.g., "192.168.1.1").
Single IPs are treated as /32.
sourceraw docstring

port->u16clj

(port->u16 port)

Convert port to unsigned 16-bit value.

Convert port to unsigned 16-bit value.
sourceraw docstring

port-valid?clj

(port-valid? port)

Check if port number is valid (1-65535).

Check if port number is valid (1-65535).
sourceraw docstring

resolve-hostnameclj

(resolve-hostname hostname)

Resolve hostname to IP address (u32). Returns nil if resolution fails.

Resolve hostname to IP address (u32).
Returns nil if resolution fails.
sourceraw docstring

resolve-hostname-allclj

(resolve-hostname-all hostname)

Resolve hostname to ALL A records (not just first). Returns vector of u32 IPs, or nil if resolution fails.

This is useful for DNS-based load balancing where a hostname may resolve to multiple backend IPs.

Resolve hostname to ALL A records (not just first).
Returns vector of u32 IPs, or nil if resolution fails.

This is useful for DNS-based load balancing where a hostname
may resolve to multiple backend IPs.
sourceraw docstring

resolve-to-ipclj

(resolve-to-ip source-spec)

Resolve a source specification to IP. Accepts: IP string, CIDR string, or hostname. Returns {:ip <u32> :prefix-len <int>} or nil on failure.

Resolve a source specification to IP.
Accepts: IP string, CIDR string, or hostname.
Returns {:ip <u32> :prefix-len <int>} or nil on failure.
sourceraw docstring

SNI-KEY-SIZEclj

source

TC-ACT-OKclj

source

TC-ACT-REDIRECTclj

source

TC-ACT-SHOTclj

source

TCP-HLEN-MINclj

source

u32->ip-stringclj

(u32->ip-string n)

Convert network byte order u32 to dotted-decimal IP string. Example: 0xC0A80101 => "192.168.1.1"

Convert network byte order u32 to dotted-decimal IP string.
Example: 0xC0A80101 => "192.168.1.1"
sourceraw docstring

UDP-HLENclj

source

WEIGHTED-ROUTE-HEADER-SIZEclj

source

WEIGHTED-ROUTE-MAX-SIZEclj

source

WEIGHTED-ROUTE-MAX-TARGETSclj

source

WEIGHTED-ROUTE-TARGET-SIZEclj

source

weighted-route-value-sizeclj

(weighted-route-value-size)

Return the fixed size of weighted route values (72 bytes). All weighted routes use the same size for BPF map compatibility.

Return the fixed size of weighted route values (72 bytes).
All weighted routes use the same size for BPF map compatibility.
sourceraw docstring

XDP-ABORTEDclj

source

XDP-DROPclj

source

XDP-PASSclj

source

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