Liking cljdoc? Tell your friends :D
Clojure only.

lb.util

Utility functions for IP address conversion, CIDR parsing, and binary encoding. Supports both IPv4 and IPv6 addresses with unified 16-byte internal format.

Utility functions for IP address conversion, CIDR parsing, and binary encoding.
Supports both IPv4 and IPv6 addresses with unified 16-byte internal format.
raw docstring

address-familyclj

(address-family ip-str)

Determine address family from IP string. Returns :ipv4, :ipv6, or nil if invalid.

Determine address family from IP string.
Returns :ipv4, :ipv6, or nil if invalid.
sourceraw docstring

bytes->ipclj

(bytes->ip b)

Convert 4-byte array to IP u32.

Convert 4-byte array to IP u32.
sourceraw docstring

bytes->ipv6-stringclj

(bytes->ipv6-string b)

Convert 16-byte array to IPv6 string. Example: [32 1 13 184 0 0 0 0 0 0 0 0 0 0 0 1] => "2001:db8::1"

Convert 16-byte array to IPv6 string.
Example: [32 1 13 184 0 0 0 0 0 0 0 0 0 0 0 1] => "2001:db8::1"
sourceraw docstring

bytes16->address-familyclj

(bytes16->address-family b)

Determine address family from unified 16-byte format. Returns :ipv4 if first 12 bytes are zero, :ipv6 otherwise.

Determine address family from unified 16-byte format.
Returns :ipv4 if first 12 bytes are zero, :ipv6 otherwise.
sourceraw docstring

bytes16->ip-stringclj

(bytes16->ip-string b)

Convert unified 16-byte format back to IP string. Detects IPv4 (zero-prefixed) vs IPv6.

Convert unified 16-byte format back to IP string.
Detects IPv4 (zero-prefixed) vs IPv6.
sourceraw docstring

bytes16-zero?clj

(bytes16-zero? b)

Check if unified 16-byte address is all zeros.

Check if unified 16-byte address is all zeros.
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

cidr-unified->stringclj

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

Convert unified CIDR {:ip <bytes16> :prefix-len :af} back to string.

Convert unified CIDR {:ip <bytes16> :prefix-len :af} back to string.
sourceraw docstring

CONNTRACK-KEY-UNIFIED-SIZEclj

source

CONNTRACK-VALUE-UNIFIED-SIZEclj

source

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-key-unifiedclj

(decode-conntrack-key-unified b)

Decode unified connection tracking key from byte array.

Decode unified 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-conntrack-value-unifiedclj

(decode-conntrack-value-unified b)

Decode unified connection tracking value from byte array (96 bytes).

Decode unified connection tracking value from byte array (96 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-listen-key-unifiedclj

(decode-listen-key-unified b)

Decode unified listen map key from byte array.

Decode unified 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-lpm-key-unifiedclj

(decode-lpm-key-unified b)

Decode unified LPM trie key from byte array. Returns {:prefix-len :ip (16-byte array) :af}.

Decode unified LPM trie key from byte array.
Returns {:prefix-len :ip (16-byte array) :af}.
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

decode-weighted-route-value-unifiedclj

(decode-weighted-route-value-unified b)

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

Decode unified weighted route value from byte array (168 bytes).
Returns {:target-count :flags :targets} where targets is a vector of
{:ip <16-byte-array> :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-key-unifiedclj

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

Encode unified connection tracking 5-tuple key. {src_ip (16) + dst_ip (16) + src_port (2) + dst_port (2) + protocol (1) + padding (3)} Total: 40 bytes (aligned). src-ip and dst-ip must be 16-byte arrays.

Encode unified connection tracking 5-tuple key.
{src_ip (16) + dst_ip (16) + src_port (2) + dst_port (2) + protocol (1) + padding (3)}
Total: 40 bytes (aligned).
src-ip and dst-ip must be 16-byte arrays.
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-conntrack-value-unifiedclj

(encode-conntrack-value-unified
  {: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 unified connection tracking value. {orig_dst_ip (16) + orig_dst_port (2) + padding (2) + nat_dst_ip (16) + 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: 96 bytes. IPs in network byte order, counters in native order.

Encode unified connection tracking value.
{orig_dst_ip (16) + orig_dst_port (2) + padding (2) + nat_dst_ip (16) + 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: 96 bytes.
IPs in network byte order, 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-listen-key-unifiedclj

(encode-listen-key-unified ifindex port af)

Encode unified listen map key: {ifindex (4 bytes) + port (2 bytes) + af (1 byte) + pad (1 byte)}. Total: 8 bytes (same size as before, but includes address family). af is :ipv4 or :ipv6.

Encode unified listen map key: {ifindex (4 bytes) + port (2 bytes) + af (1 byte) + pad (1 byte)}.
Total: 8 bytes (same size as before, but includes address family).
af is :ipv4 or :ipv6.
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-lpm-key-unifiedclj

(encode-lpm-key-unified prefix-len ip-bytes16)

Encode unified LPM trie key: {prefix_len (4 bytes) + ip (16 bytes)}. Total: 20 bytes. ip-bytes16 must be a 16-byte array in unified format.

Encode unified LPM trie key: {prefix_len (4 bytes) + ip (16 bytes)}.
Total: 20 bytes.
ip-bytes16 must be a 16-byte array in unified format.
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

encode-weighted-route-value-unifiedclj

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

Encode unified weighted route value for BPF map. target-group has :targets with :ip as 16-byte arrays, and :cumulative-weights. flags is optional (default 0).

Format (max 168 bytes):

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

IP bytes are stored in network byte order (big-endian).

Encode unified weighted route value for BPF map.
target-group has :targets with :ip as 16-byte arrays, and :cumulative-weights.
flags is optional (default 0).

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

IP bytes are stored in network byte order (big-endian).
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). Handles unsigned u32 values that may exceed Integer/MAX_VALUE.

Convert IP u32 to byte array (4 bytes, big-endian).
Handles unsigned u32 values that may exceed Integer/MAX_VALUE.
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->bytes16clj

(ip-string->bytes16 ip-str)

Parse IPv4 or IPv6 string to unified 16-byte format. IPv4: padded with 12 zero bytes prefix IPv6: native 16 bytes

Parse IPv4 or IPv6 string to unified 16-byte format.
IPv4: padded with 12 zero bytes prefix
IPv6: native 16 bytes
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-ICMPV6clj

source

IPPROTO-TCPclj

source

IPPROTO-UDPclj

source

ipv4-bytes->bytes16clj

(ipv4-bytes->bytes16 ipv4-bytes)

Pad 4-byte IPv4 address to 16 bytes with zero prefix. Format: 00:00:00:00:00:00:00:00:00:00:00:00:AA:BB:CC:DD

Pad 4-byte IPv4 address to 16 bytes with zero prefix.
Format: 00:00:00:00:00:00:00:00:00:00:00:00:AA:BB:CC:DD
sourceraw docstring

ipv4?clj

(ipv4? ip-str)

Check if string is an IPv4 address (dotted decimal, no colons).

Check if string is an IPv4 address (dotted decimal, no colons).
sourceraw docstring

IPV6-HLENclj

source

ipv6-string->bytesclj

(ipv6-string->bytes ipv6-str)

Convert IPv6 string to 16-byte array. Uses Java's InetAddress for robust parsing (handles all IPv6 formats). Example: "2001:db8::1" => [32 1 13 184 0 0 0 0 0 0 0 0 0 0 0 1]

Convert IPv6 string to 16-byte array.
Uses Java's InetAddress for robust parsing (handles all IPv6 formats).
Example: "2001:db8::1" => [32 1 13 184 0 0 0 0 0 0 0 0 0 0 0 1]
sourceraw docstring

ipv6?clj

(ipv6? ip-str)

Check if string is an IPv6 address (contains colon).

Check if string is an IPv6 address (contains colon).
sourceraw docstring

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

LISTEN-KEY-UNIFIED-SIZEclj

source

LPM-KEY-UNIFIED-SIZEclj

source

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

parse-cidr-unifiedclj

(parse-cidr-unified cidr-str)

Parse CIDR notation string for IPv4 or IPv6. Returns {:ip <16-byte-array> :prefix-len <int> :af <:ipv4|:ipv6>}

Examples: "192.168.1.0/24" => {:ip <bytes16> :prefix-len 24 :af :ipv4} "2001:db8::/32" => {:ip <bytes16> :prefix-len 32 :af :ipv6} "192.168.1.1" => {:ip <bytes16> :prefix-len 32 :af :ipv4} "2001:db8::1" => {:ip <bytes16> :prefix-len 128 :af :ipv6}

Parse CIDR notation string for IPv4 or IPv6.
Returns {:ip <16-byte-array> :prefix-len <int> :af <:ipv4|:ipv6>}

Examples:
  "192.168.1.0/24"      => {:ip <bytes16> :prefix-len 24 :af :ipv4}
  "2001:db8::/32"       => {:ip <bytes16> :prefix-len 32 :af :ipv6}
  "192.168.1.1"         => {:ip <bytes16> :prefix-len 32 :af :ipv4}
  "2001:db8::1"         => {:ip <bytes16> :prefix-len 128 :af :ipv6}
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-hostname-all-bytes16clj

(resolve-hostname-all-bytes16 hostname)

Resolve hostname to ALL records in unified 16-byte format. Returns vector of 16-byte arrays, or nil if resolution fails.

Resolve hostname to ALL records in unified 16-byte format.
Returns vector of 16-byte arrays, or nil if resolution fails.
sourceraw docstring

resolve-hostname-bytes16clj

(resolve-hostname-bytes16 hostname)

Resolve hostname to 16-byte unified format. Works for both IPv4 and IPv6 hostnames. Returns nil if resolution fails.

Resolve hostname to 16-byte unified format.
Works for both IPv4 and IPv6 hostnames.
Returns nil if resolution fails.
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->bytes16clj

(u32->bytes16 ip-u32)

Convert IPv4 u32 to 16-byte unified format.

Convert IPv4 u32 to 16-byte unified format.
sourceraw docstring

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-TARGET-UNIFIED-SIZEclj

source

WEIGHTED-ROUTE-UNIFIED-MAX-SIZEclj

source

weighted-route-unified-value-sizeclj

(weighted-route-unified-value-size)

Return the fixed size of unified weighted route values (168 bytes).

Return the fixed size of unified weighted route values (168 bytes).
sourceraw docstring

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