Skip to content

Server: count an IPv6 /64 as one address for the per-address connection limit - #164

Merged
undecuple merged 2 commits into
mainfrom
fork-conn-cap
Nov 13, 2026
Merged

undecuple merged 2 commits into
mainfrom
fork-conn-cap

Conversation

@undecuple

Copy link
Copy Markdown
Owner

Why

-max-conns-per-addr counted each exact remote address. For IPv6 that is not one source: a single network (a /64) holds billions of addresses, so connections from different addresses of one network each got a full allowance. The UDP limit and the admin failure delay already treat an IPv6 /64 as one source; the TCP per-address limit did not.

Change

  • server/server.go: addrLimitKey gives the key the limit counts by: an IPv4 address (an IPv4-mapped address counts as the IPv4 address), or an IPv6 address cut to its /64, with any zone dropped. The count is taken and released under that key. The address a player is known by (rooms, peers, logs, the public_ip sent to the client) is unchanged; only the counting key changes.
  • Players behind one IPv6 /64, such as one LAN, now share the limit, as players behind one IPv4 address always did. Raise -max-conns-per-addr if 32 is too tight for such a group.
  • docs/running.md, README.md, docs/api.md and the -help text say that an IPv6 address counts as its /64. CHANGELOG Server: entry under Fixed; site/ regenerated.

Tests

  • server/conn_cap_key_test.go: a table for the key (IPv4, IPv4-mapped, two addresses of one /64, another /64, a zone); with a limit of 2 behind a trusted proxy, a third address of the same /64 is refused, another /64 is served, and IPv4 behaves as before; and a count is released under the same key, so the table empties when the connection closes and the allowance is free again.
  • gofmt, go vet, go test ./server, python3 tools/repo_check.py, python3 tools/site.py --check, python3 tools/features.py --check and scripts/check-deploy.sh pass.
  • Mutation-tested: counting by the exact address when admitting, releasing under a different key, not unmapping, and a /56 or /128 cut each fail a test. Against main the new tests do not build, because addrLimitKey does not exist there.

Not in this change

No new flag, no change to the default of 32, and no change to the UDP limit or the admin delay.

Overlap

None open on server/server.go. Other open work touches CHANGELOG.md and the generated site files, so whichever merges later needs a rebase. Based on main at 7fdd762.

Developed with AI agent assistance.

@undecuple
undecuple merged commit bc0fd12 into main Nov 13, 2026
10 checks passed
@undecuple
undecuple deleted the fork-conn-cap branch November 13, 2026 03:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant