Rate limit IPv6 by the /64, not the address¶
My gateway had a rate limiter that did nothing for IPv6 clients. I wrote it, and I should have known better.
The limiter in r7 is a token bucket per client, and the client was the IP address. For IPv4 that is fine. One address is roughly one client, or one office behind NAT.
For IPv6 it is wrong, and not by a little. A subscriber is normally given a whole /64. That is 2⁶⁴ addresses, about 18 quintillion, and the client can use any of them. So a client that wants to get past the limit takes a new address for every request, and gets a new, full bucket each time.
It is worse than no limit. The limiter keeps a bucket per address in memory, up to max_buckets. So the same client that walks past the limit also fills the table and pushes out the buckets of everyone else.
This is kinda humiliating. It is not obscure. I have known how IPv6 addresses are handed out for years, and I still wrote "per address" without thinking, the way I have always done it for IPv4.
The fix¶
IPv6 clients are now keyed by the leading 64 bits. IPv4 clients are keyed by the full address as before.
64 is the default, so you do not have to set it. You can lower it to 56 or 48 if you see providers that hand out more than a /64 per customer.
It was fixed before the first beta. If you have a rate limiter of your own, look at what it uses as the key.