embassy icon indicating copy to clipboard operation
embassy copied to clipboard

Dynamic port allocation

Open arturkow2000 opened this issue 3 years ago • 2 comments

Embassy-net currently allocates ports starting with port 1025 (LOCAL_PORT_MIN variable), this may conflict with services that use ports higher than 1025, combined with RNG which IIRC is already used for randomizing ports, may cause random failures in apps. Shouldn't embassy-net allocate only ports from 49152 to 65535 range?

arturkow2000 avatar Aug 10 '22 17:08 arturkow2000

It depends on which standard you follow, but I think the IANA range as you suggest is nicer and less surprising than starting at 1025.

lulf avatar Aug 10 '22 18:08 lulf

For TCP this is very unlikely to cause issues. What identifies a connection is the 4-tuple (src ip, src port, dst ip, dst port), so you can have a client connection with src port 1234 and a server listening on port 1234 just fine.

For UDP this can be a problem, yes. It can still be a problem if you open so many sockets that you get 2 with the same src port by chance though, so changing the port range doesn't really fix the issue.

I think the right fix would be to explicitly check for conflicts when generating the random src port: generate one, if it's already used retry.

Dirbaio avatar Aug 10 '22 18:08 Dirbaio