3 ms·
There is an extra condition for the new port, it must not have been used recently, because attempting a new connection with a port used previously might hit a p
by adrian_b 4y ago
There is an extra condition for the new port, it must not have been used recently, because attempting a new connection with a port used previously might hit a previous connection on the server that has not been deleted yet and it is still in the TIME-WAIT state.
The obvious and correct solution is to keep a list with the recently used ports, with an expiration time after a connection has been closed, and to reject any new random port that can be found in that list.
RFC 6056 claims that the obvious solution is inefficient, so it is better to increment some previously used port, to get a new distinct port.
Judging from the large overhead that is needed for fixing the "efficient" solution, I believe that it would have been better to just implement the right solution, which is likely to need less state.