Skip to contentSkip to conversation

tcp port reuse checking TCP_LISTEN state

DISCUSSION Ilya Pashkovsky 2 participants 3 messages Nov 23, 2004 – Nov 27, 2004

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Hello, fellow developers.

While BSD (and thus, MacOS X) has the SO_REUSEPORT socket option, and Windows has SO_REUSEADDR socket option that integrates the port reuse functionality, linux tends to differ.
Though the socket matching should be made using the tuple consisting of both source address+port and destination address+port, there's a check in the tcp implementation of linux kernel for TCP_LISTEN state, which inhibits port reuse. While its logical to allow only one listener on a socket, this can be accomplished by checking for the socket state during the call to listen(). The current behavior breaks applications that want to both listen on an port and initiate outgoing connections from it (same port).
Can anyone please explain the logic behind the TCP_LISTEN check being done on bind() calls and not listen() calls ?

--
ilya

#1 lore raw
Quoted 5 lines · Ilya Pashkovsky

Hello, fellow developers.

While BSD (and thus, MacOS X) has the SO_REUSEPORT socket option, and Windows has SO_REUSEADDR socket option that integrates the port reuse functionality, linux tends to differ.

You should probably ask [email protected] as that is where most networking developers hang out

#2 lore raw
In reply to Ilya Pashkovsky

Hello, fellow developers.

While BSD (and thus, MacOS X) has the SO_REUSEPORT socket option, and Windows has SO_REUSEADDR socket option that integrates the port reuse functionality, linux tends to differ.
Though the socket matching should be made using the tuple consisting of both source address+port and destination address+port, there's a check in the tcp implementation of linux kernel for TCP_LISTEN state, which inhibits port reuse. While its logical to allow only one listener on a socket, this can be accomplished by checking for the socket state during the call to listen(). The current behavior breaks applications that want to both listen on an port and initiate outgoing connections from it (same port).
Can anyone please explain the logic behind the TCP_LISTEN check being done on bind() calls and not listen() calls ?

p.s. Please cc your reply directly to [email protected]

--
ilya