Skip to main content

subnet_key

Function subnet_key 

Source
pub fn subnet_key(
    address: &IpAddr,
    ipv4_prefix: u32,
    ipv6_prefix: u32,
) -> IpAddr
Expand description

Derive the per-(cluster, source-SUBNET) counter key for address.

An IPv4-mapped IPv6 address is canonicalised to its IPv4 form and charged to ipv4_prefix. This matters: a dual-stack [::] listener hands every IPv4 client back as ::ffff:a.b.c.d, and masking those with an IPv6 prefix would collapse the entire IPv4 internet into the single ::/56 bucket — the subnet cap would then fire on unrelated clients the moment it was switched on. The per-IP counter is NOT canonicalised: it keeps charging the address exactly as it arrived, which is part of what leaves its behaviour untouched by this feature.