IPv6 address loading helpers for packet parsing.
IPv6 addresses are 16 bytes and require multiple load/store operations. These helpers simplify loading IPv6 addresses from packets to stack and provide a 'unified' format for dual-stack (IPv4/IPv6) handling.
Usage: (require '[clj-ebpf.net.ipv6 :as ipv6])
;; Load IPv6 source address from packet to stack (ipv6/build-load-ipv6-address :r9 ipv6/IPV6-OFF-SRC -84)
;; Load IPv4 address in unified 16-byte format (ipv6/build-load-ipv4-unified :r9 12 -84)
IPv6 address loading helpers for packet parsing. IPv6 addresses are 16 bytes and require multiple load/store operations. These helpers simplify loading IPv6 addresses from packets to stack and provide a 'unified' format for dual-stack (IPv4/IPv6) handling. Usage: (require '[clj-ebpf.net.ipv6 :as ipv6]) ;; Load IPv6 source address from packet to stack (ipv6/build-load-ipv6-address :r9 ipv6/IPV6-OFF-SRC -84) ;; Load IPv4 address in unified 16-byte format (ipv6/build-load-ipv4-unified :r9 12 -84)
(build-copy-ipv6-address src-stack-offset dst-stack-offset)Copy 16-byte address from one stack location to another.
Useful for saving original addresses before modification.
Args: src-stack-offset: Source stack offset dst-stack-offset: Destination stack offset
Uses: r0 as scratch
Returns: Vector of 8 instructions
Copy 16-byte address from one stack location to another. Useful for saving original addresses before modification. Args: src-stack-offset: Source stack offset dst-stack-offset: Destination stack offset Uses: r0 as scratch Returns: Vector of 8 instructions
(build-load-ipv4-dst-unified ip-hdr-reg stack-offset)Load IPv4 destination address in unified 16-byte format.
Convenience wrapper around build-load-ipv4-unified for destination address.
Args: ip-hdr-reg: Register pointing to IPv4 header stack-offset: Stack destination for 16-byte unified address
Returns: Vector of 5 instructions
Load IPv4 destination address in unified 16-byte format. Convenience wrapper around build-load-ipv4-unified for destination address. Args: ip-hdr-reg: Register pointing to IPv4 header stack-offset: Stack destination for 16-byte unified address Returns: Vector of 5 instructions
(build-load-ipv4-src-unified ip-hdr-reg stack-offset)Load IPv4 source address in unified 16-byte format.
Convenience wrapper around build-load-ipv4-unified for source address.
Args: ip-hdr-reg: Register pointing to IPv4 header stack-offset: Stack destination for 16-byte unified address
Returns: Vector of 5 instructions
Load IPv4 source address in unified 16-byte format. Convenience wrapper around build-load-ipv4-unified for source address. Args: ip-hdr-reg: Register pointing to IPv4 header stack-offset: Stack destination for 16-byte unified address Returns: Vector of 5 instructions
(build-load-ipv4-unified src-reg header-offset stack-offset)Load 4-byte IPv4 address into 16-byte unified format.
Creates IPv4-mapped address: zeros first 12 bytes, then stores 4-byte IPv4. This allows using the same data structures for IPv4 and IPv6.
The format is: 00 00 00 00 00 00 00 00 00 00 00 00 <IPv4 address>
Args: src-reg: Register pointing to IP header header-offset: Offset to IPv4 address (12 for src, 16 for dst in IPv4 header) stack-offset: Stack destination for 16-byte unified address
Uses: r0 as scratch
Returns: Vector of 5 instructions
Example: ;; Load IPv4 source (at header+12) in unified format (build-load-ipv4-unified :r9 12 -84) ;; Result at stack[-84..-69]: 00 00 00 00 00 00 00 00 00 00 00 00 AA BB CC DD
Load 4-byte IPv4 address into 16-byte unified format. Creates IPv4-mapped address: zeros first 12 bytes, then stores 4-byte IPv4. This allows using the same data structures for IPv4 and IPv6. The format is: 00 00 00 00 00 00 00 00 00 00 00 00 <IPv4 address> Args: src-reg: Register pointing to IP header header-offset: Offset to IPv4 address (12 for src, 16 for dst in IPv4 header) stack-offset: Stack destination for 16-byte unified address Uses: r0 as scratch Returns: Vector of 5 instructions Example: ;; Load IPv4 source (at header+12) in unified format (build-load-ipv4-unified :r9 12 -84) ;; Result at stack[-84..-69]: 00 00 00 00 00 00 00 00 00 00 00 00 AA BB CC DD
(build-load-ipv6-address src-reg header-offset stack-offset)Generate instructions to load a 16-byte IPv6 address from packet to stack.
Loads 4 consecutive 32-bit words from packet memory and stores them contiguously on the stack.
Args: src-reg: Register pointing to the IP header (or base for offset) header-offset: Offset from src-reg to the address field (e.g., IPV6-OFF-SRC=8 for source, IPV6-OFF-DST=24 for dest) stack-offset: Stack offset where to store (stores 16 bytes starting here)
Uses: r0 as scratch (clobbered)
Returns: Vector of 8 instructions
Example: ;; r9 points to IPv6 header, load source address to stack[-84] (build-load-ipv6-address :r9 IPV6-OFF-SRC -84) ;; Loads from r9+8, r9+12, r9+16, r9+20 ;; Stores to stack[-84], stack[-80], stack[-76], stack[-72]
Generate instructions to load a 16-byte IPv6 address from packet to stack.
Loads 4 consecutive 32-bit words from packet memory and stores them
contiguously on the stack.
Args:
src-reg: Register pointing to the IP header (or base for offset)
header-offset: Offset from src-reg to the address field
(e.g., IPV6-OFF-SRC=8 for source, IPV6-OFF-DST=24 for dest)
stack-offset: Stack offset where to store (stores 16 bytes starting here)
Uses: r0 as scratch (clobbered)
Returns: Vector of 8 instructions
Example:
;; r9 points to IPv6 header, load source address to stack[-84]
(build-load-ipv6-address :r9 IPV6-OFF-SRC -84)
;; Loads from r9+8, r9+12, r9+16, r9+20
;; Stores to stack[-84], stack[-80], stack[-76], stack[-72](build-load-ipv6-address-adjusted src-reg base-offset field-offset stack-offset)Load IPv6 address with offset adjustment for non-standard pointer positions.
Use when src-reg doesn't point to the IP header start. The base-offset adjusts for the difference.
Args: src-reg: Register pointing to packet data (may not be at IP header) base-offset: Adjustment from src-reg to IP header start (can be negative) field-offset: Field offset within IPv6 header (IPV6-OFF-SRC or IPV6-OFF-DST) stack-offset: Stack destination
Uses: r0 as scratch
Returns: Vector of 8 instructions
Example: ;; r9 = data + 58 (pointing at L4 header) ;; IPv6 header at data + 14 ;; Adjustment: 14 - 58 = -44 (build-load-ipv6-address-adjusted :r9 -44 IPV6-OFF-SRC -56)
Load IPv6 address with offset adjustment for non-standard pointer positions. Use when src-reg doesn't point to the IP header start. The base-offset adjusts for the difference. Args: src-reg: Register pointing to packet data (may not be at IP header) base-offset: Adjustment from src-reg to IP header start (can be negative) field-offset: Field offset within IPv6 header (IPV6-OFF-SRC or IPV6-OFF-DST) stack-offset: Stack destination Uses: r0 as scratch Returns: Vector of 8 instructions Example: ;; r9 = data + 58 (pointing at L4 header) ;; IPv6 header at data + 14 ;; Adjustment: 14 - 58 = -44 (build-load-ipv6-address-adjusted :r9 -44 IPV6-OFF-SRC -56)
(build-load-ipv6-dst ip-hdr-reg stack-offset)Load IPv6 destination address from packet to stack.
Args: ip-hdr-reg: Register pointing to IPv6 header stack-offset: Stack destination
Returns: Vector of 8 instructions
Load IPv6 destination address from packet to stack. Args: ip-hdr-reg: Register pointing to IPv6 header stack-offset: Stack destination Returns: Vector of 8 instructions
(build-load-ipv6-src ip-hdr-reg stack-offset)Load IPv6 source address from packet to stack.
Args: ip-hdr-reg: Register pointing to IPv6 header stack-offset: Stack destination
Returns: Vector of 8 instructions
Load IPv6 source address from packet to stack. Args: ip-hdr-reg: Register pointing to IPv6 header stack-offset: Stack destination Returns: Vector of 8 instructions
(build-store-ipv6-address stack-offset dst-reg header-offset)Store 16-byte address from stack back to packet.
Useful for NAT or address rewriting.
Args: stack-offset: Source stack offset dst-reg: Register pointing to destination in packet header-offset: Offset from dst-reg to write location
Uses: r0 as scratch
Returns: Vector of 8 instructions
Store 16-byte address from stack back to packet. Useful for NAT or address rewriting. Args: stack-offset: Source stack offset dst-reg: Register pointing to destination in packet header-offset: Offset from dst-reg to write location Uses: r0 as scratch Returns: Vector of 8 instructions
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |