On Mon, Sep 9, 2013 at 4:41 PM, Antony Stone <Antony.Stone@xxxxxxxxxxxxxxxxxxxx> wrote: > On Monday 09 September 2013 at 13:08:00, Nikolai Gorchilov wrote: > >> On Mon, Sep 9, 2013 at 4:15 PM, Nikolai Gorchilov <niki@xxxxxxxx> wrote: >> > User's original port seems to be an easy option in TPROXY mode >> >> I did a simple test and found the kernel will emit EADDRINUSE when you >> bind on user's ip:port... So, a more complicated solution is needed. >> Keeping track of all the used ports per IP (both users, and already >> auto-selected by the software) and auto-select from the remaining... >> >> :( > > Or perhaps attempt binding to randomly selected IP:port combinations until you > don't get EADDRINUSE back? Yeah, a little bit dirty, but working solution. Just realised that keeping track of IP:port pairs in use at application level is useless, as there could be other software (or workers) running on the same machine and there's no practical way all to share all this information among them. Seems, the best place to keep track of all ip:port utilisation is in the kernel - the only piece of software that knows everything :( Niki