❦ 23 février 2014 12:25 CET, Willy Tarreau <[email protected]> :

>> I suppose this is in combination with SO_REUSEADDR (otherwise, bind()
>> would fail). It's good to know:
>> 
>> tcp    ESTAB      0      0          192.168.116.1:37544    74.125.132.104:80 
>>    
>> tcp    ESTAB      0      0          192.168.116.1:37544    74.125.132.106:80 
>>    
>
> You don't even need SO_REUSEADDR nor SO_REUSEPORT for this. This is
> standard. For example, FTP servers in active mode all need to bind
> to source port 20 and connect to the remote.

I just tried this on Linux 3.12:

In [69]: s1 = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)              
                                          

In [70]: s2 = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)              
                                          

In [71]: s1.bind(("0.0.0.0", 37546))                                            
                                          

In [72]: s2.bind(("0.0.0.0", 37546))                                            
                                          
---------------------------------------------------------------------------
error                                     Traceback (most recent call last)
<ipython-input-72-9d64edf0584f> in <module>()
----> 1 s2.bind(("0.0.0.0", 37546))

/usr/lib/python2.7/socket.pyc in meth(name, self, *args)
    222 
    223 def meth(name,self,*args):
--> 224     return getattr(self._sock,name)(*args)
    225 
    226 for _m in _socketmethods:

error: [Errno 98] Address already in use

>> As for getting the same stuff without explictely use bind(), I just
>> tried with a 3.2 and I am able to get in the same situation without
>> bind() nor SO_REUSEADDR option:
>> 
>> tcp    ESTAB      0      0           10.234.78.65:61000      10.234.78.67:80 
>>    
>> tcp    ESTAB      0      0           10.234.78.65:61000      10.234.78.66:80 
>>    
>
> OK so it confirms that it's really 3.2 which first worked on this.

I am too lazy to find the first kernel which works. Looking at the
commits, I have found 2b05ad (tcp: bind() fix autoselection to share
ports) which may fit the description but it appears in Linux 3.3-rc2 and
was not backported to 3.2 stable. So, my best guess is fda48a (tcp:
bind() fix when many ports are bound) but it appeared in 2.6.34-rc6.
-- 
Don't over-comment.
            - The Elements of Programming Style (Kernighan & Plauger)

Reply via email to