Skip to main content

connection_limit_key

Function connection_limit_key 

Source
pub(crate) fn connection_limit_key(ip: IpAddr) -> IpAddr
Expand description

Returns the peer group key for an IP address: the set of addresses Zebra treats as one entity.

Used to enforce Config::max_connections_per_ip, and to apply misbehavior bans.

  • IPv4: the address itself. Each address costs an attacker a separate IPv4 allocation, so it already bounds a single host’s share.
  • IPv6: the /64 prefix — the lower 64 bits are zeroed. A standard IPv6 /64 allocation holds 2⁶⁴ addresses that can all belong to one host, so exact-address comparison would not bound a single host’s share.
  • IPv4-mapped IPv6 addresses map to their plain IPv4 address, so both spellings share one key.

The port is always dropped, so a peer cannot get a fresh key by reconnecting from a different source port.

§Security

Connection limits and bans are only as strong as this grouping. Every limit and ban check must key peers through this function.