hyperlane-plugin-ip-filter 23.3.1

A zero-allocation IP allowlist/denylist and anti-spoofing client IP extraction plugin for the Hyperlane framework with /8 radix-indexed CIDR lookup, IPv4-mapped IPv6 canonicalization, RFC 7239 Forwarded/X-Forwarded-For right-to-left proxy peeling, and prebuilt 403 wire responses.
Documentation
/// Context attribute key storing the resolved [`ClientIp`](crate::ClientIp) metadata.
pub const ATTR_CLIENT_IP: &str = "hyperlane_plugin_client_ip";

/// Default response body emitted when a request IP is rejected.
pub const DEFAULT_REJECT_BODY: &[u8] = b"Forbidden";

/// Default `Content-Type` header emitted on rejected requests.
pub const DEFAULT_REJECT_CONTENT_TYPE: &str = "text/plain; charset=utf-8";

/// Default maximum number of trusted proxy hops peeled right-to-left.
pub const DEFAULT_MAX_TRUSTED_HOPS: usize = 16;

/// Number of `/8` radix buckets in [`CidrTable`].
pub(crate) const CIDR_BUCKET_COUNT: usize = 256;

/// Length of the CSR `/8` bucket offset table (`CIDR_BUCKET_COUNT + 1`).
pub(crate) const CIDR_OFFSET_LEN: usize = CIDR_BUCKET_COUNT + 1;

/// Maximum merged interval count stored inline inside [`CidrTable`] without heap allocation.
pub(crate) const CIDR_INLINE_LIMIT: usize = 4;

/// Maximum per-bucket interval count scanned linearly before binary searching.
pub(crate) const CIDR_BUCKET_LINEAR_LIMIT: usize = 4;

/// Threshold above which exact exempt paths switch from linear slice scan to hash set.
pub(crate) const EXEMPT_SET_THRESHOLD: usize = 4;

/// Maximum CIDR prefix length for IPv4 addresses.
pub(crate) const IPV4_MAX_PREFIX: u8 = 32;

/// Maximum CIDR prefix length for IPv6 addresses.
pub(crate) const IPV6_MAX_PREFIX: u8 = 128;

/// Mask covering the host 24 bits inside one IPv4 `/8` block.
pub(crate) const IPV4_SLASH8_HOST_MASK: u32 = 0x00FF_FFFF;

/// Mask covering the host 120 bits inside one IPv6 `/8` block.
pub(crate) const IPV6_SLASH8_HOST_MASK: u128 = (1u128 << 120) - 1;

/// Prefix length of the IPv4-mapped IPv6 subnet `::ffff:0:0/96`.
pub(crate) const IPV4_MAPPED_PREFIX_BITS: u8 = 96;

/// Leading 96-bit pattern identifying an IPv4-mapped IPv6 address.
pub(crate) const IPV4_MAPPED_HIGH_96: u128 = 0x0000_0000_0000_0000_0000_ffff_0000_0000;

/// Mask extracting the upper 96 bits of an IPv6 address.
pub(crate) const IPV6_HIGH_96_MASK: u128 = 0xffff_ffff_ffff_ffff_ffff_ffff_0000_0000;

/// RFC 7239 `Forwarded` directive prefix selecting the client address parameter.
pub(crate) const FORWARDED_FOR_PREFIX: &str = "for=";

/// RFC 7239 sentinel token denoting an unknown forwarded address.
pub(crate) const FORWARDED_UNKNOWN: &str = "unknown";

/// Error message returned when parsing an empty CIDR string.
pub(crate) const ERR_EMPTY_CIDR: &str = "empty CIDR specification";

/// Error message returned when the IP address part of a CIDR fails to parse.
pub(crate) const ERR_INVALID_IP: &str = "invalid IP address in CIDR";

/// Error message returned when the prefix length fails to parse as an integer.
pub(crate) const ERR_INVALID_PREFIX: &str = "invalid CIDR prefix length";

/// Error message returned when the prefix length exceeds the address family width.
pub(crate) const ERR_PREFIX_OUT_OF_RANGE: &str = "CIDR prefix length out of range";

/// ASCII digit zero byte (`0`).
pub(crate) const ASCII_ZERO: u8 = b'0';

/// ASCII dot byte (`.`).
pub(crate) const ASCII_DOT: u8 = b'.';

/// ASCII colon byte (`:`).
pub(crate) const ASCII_COLON: u8 = b':';

/// ASCII double quote byte (`"`).
pub(crate) const ASCII_QUOTE: u8 = b'"';

/// ASCII underscore byte (`_`).
pub(crate) const ASCII_UNDERSCORE: u8 = b'_';

/// ASCII opening bracket byte (`[`).
pub(crate) const ASCII_LBRACKET: u8 = b'[';

/// ASCII semicolon byte (`;`).
pub(crate) const ASCII_SEMICOLON: u8 = b';';

/// ASCII lowercase `'f'` byte for RFC 7239 `for=` matching.
pub(crate) const ASCII_LOWER_F: u8 = b'f';

/// ASCII lowercase `'o'` byte for RFC 7239 `for=` matching.
pub(crate) const ASCII_LOWER_O: u8 = b'o';

/// ASCII lowercase `'r'` byte for RFC 7239 `for=` matching.
pub(crate) const ASCII_LOWER_R: u8 = b'r';

/// ASCII equals byte (`=`).
pub(crate) const ASCII_EQUALS: u8 = b'=';

/// ASCII comma byte (`,`).
pub(crate) const ASCII_COMMA: u8 = b',';

/// ASCII forward-slash byte (`/`).
pub(crate) const ASCII_SLASH: u8 = b'/';