fix(edge): IPv6 bind, configurable relay idle, per-gateway budget, PROXY identity

- bind.address is parsed as IpAddr (no ":::port"), the socket domain follows
  the family, and "::" binds dual-stack. IPv6 was impossible before.
- limits.relay_idle_timeout_secs (default 300, 1..=86400) replaces the
  hardcoded relay constant; the deploy examples document it.
- The connection budget is an Arc<Semaphore> owned by Gateway instead of a
  process-wide OnceLock, so tests and multiple gateways stay independent.
- PROXY header identity is validated: unspecified, loopback, link-local,
  multicast, broadcast and addresses inside trusted_cidrs are rejected, and
  IPv4-mapped IPv6 is normalised first. An invalid header falls back to the
  transport peer. Bans targeting trusted_cidrs are suppressed, closing the
  ban-amplification path through a trusted load balancer.
- TrustedProxyCidr::contains no longer overflows its mask for IPv6 prefixes
  shorter than /96.
This commit is contained in:
Loki 2026-11-16 12:36:19 +01:00
parent 9baae25acb
commit 324ef12b27
Signed by: boba
GPG key ID: 6CDE87BC9A778D97
15 changed files with 530 additions and 76 deletions

View file

@ -8,17 +8,17 @@ use tokio::net::TcpStream;
const RELAY_BUFFER_BYTES: usize = 16 * 1024;
/// Idle budget of the client/backend relay.
///
/// Minecraft keeps one connection alive for a whole session and a legitimately
/// silent gap (menus, chunk loading, AFK timeouts) can last minutes, so 300s is
/// the safe default: it never cuts a real session and still reaps dead peers.
/// The value is a constant because `[limits]` is owned by a parallel change; it
/// is plumbed as a parameter through [`Gateway::relay_with_idle`] so a config
/// field can be wired in without touching the relay itself.
pub const RELAY_IDLE_TIMEOUT: Duration = Duration::from_secs(300);
impl Gateway {
/// Returns the configured idle budget of the client/backend relay.
///
/// `limits.relay_idle_timeout_secs` defaults to 300s: Minecraft keeps one
/// connection alive for a whole session and a legitimately silent gap
/// (menus, chunk loading, AFK timeouts) can last minutes, so a short budget
/// would cut real sessions while a missing one would pin descriptors.
pub fn relay_idle_timeout(&self) -> Duration {
Duration::from_secs(self.config.limits.relay_idle_timeout_secs)
}
/// Relays bytes in both directions until either side closes, an I/O error
/// occurs or a direction stays silent for `idle`.
///