Re: inet_hash_connect: source port allocation

Eric Dumazet
2010-11-29T19:21:32Z

Le lundi 29 novembre 2010 à 20:07 +0100, Eric Dumazet a écrit :
> Le lundi 29 novembre 2010 à 19:46 +0100, Eric Dumazet a écrit :
> > Le lundi 29 novembre 2010 à 18:29 +0000, John Haxby a écrit :
> >
> > > Sorry, I think I phrased my question badly.
> > >
> > > inet_csk_get_port() starts its search for a free port with
> > >
> > > smallest_rover = rover = net_random() % remaining + low;
> > >
> > > whereas __inet_hash_connect() basically misses out that call to
> > > net_random() so you get a predictable port number.
> > >
> > > Is there any good reason why that is the case?
> > >
> >
> > It seems random select was done at bind() time only in commit
> > 6df716340da3a6f ([TCP/DCCP]: Randomize port selection)
> >
> > It probably should be done in autobind too.
> >
> >
>
> I'll test following patch :

Oh well, forget this, there is something about inet_sk_port_offset()
using secure_ipv4_port_ephemeral()

We want to avoid reusing same port too fast.

http://www.tcpipguide.com/free/t_TCPIPClientEphemeralPortsandClientServerApplicatio-2.htm

Port is predictable only for same destination, and if no other
connections are attempted by other threads.