Front Page
Blog
Corporate Customers
Private Customers
SEFlow
Linking
Cryptography
Privacy
Disclaimer
Impressum
BlogBlog
 
Hauptseite
Suchen

zBlog

02.11.2010
17:09

emulating SO_REUSEPORT in Linux userspace

The SO_REUSEPORT socket option can be a useful feature. Not only for multicasting applications (where it supposedly came from), or for load balancing servers (which seems to be what most people are interested in regarding this flag). It also allows for clean and simple solutions for some problems which are approached in a rather hacky way otherwise. For example when updating servers, it allows to easily avoid unavailability between stopping and starting the server, as the new server can just be started before stopping the old one.

Unfortunately, it is a non-standard socket option. And for the widely spread Linux kernels, it has not yet been integrated (apparently there was a patch to do so, but it wasn't accepted). And even if it was, it would still mean to sacrifice portability to use it.

However, POSIX allows to emulate something similar with a little effort. The listening socket descriptor can be shared between multiple processes, and it can be passed to new processes through a local domain socket. Thus, while kernels cannot always be depended on for allowing to reuse ports, applications can share these themselves for reuse.

Using boost::asio as a socket abstraction layer, I built a small library to automate this, together with an echo server implementation to demonstrate its use. The API is loosely modeled after boost::asio's acceptors (async_accept works the same way, but to start listening, an asynchronous async_connect call is needed as the process has to wait for another process to share the socket). You can check it out yourself here. And be sure to let me know your comments.

  •  
  • 2 Kommentar(e)
  •  
Gravatar: Ramon CasellasRamon Casellas
08.02.2011
19:34
SO_REUSEPORT for clients

Thank your for the post. As a Boost Asio user I am indeed interested. However, I run into a related problem very recently: I need to be able to setup TCP connections to two different servers from the same local address / port and I cannot find how to do it in Linux (other systems support SO_REUSEPORT for this).

If you ask "why?" the reason is that for a given TCP-based protocol (PCEP RFC5440) it is mandatory that nodes use TCP port 4189 as source and destination port. Also, it is typical to use a "node id" or "router id" or "loopback address". Finally a given node may be able to have two or more "peers".

In other words, even if a TCP connection should be clearly identified by the tuple (proto, srcaddr, srcport, dstaddr, dstport) I cannot figure out how to initiate 2 TCP connections with duplicate bindings (of course to different addresses) in Linux. It seems a clear use case to me :)

Gravatar: Isidor ZeunerIsidor Zeuner
22.04.2011
05:29
SO_REUSEADDR

SO_REUSEADDR allows to do this on Linux. I think it works for most traditional uses of SO_REUSEPORT.

Mein Kommentar

Ich möchte über jeden weiteren Kommentar in diesem Post benachrichtigt werden.

Zurück

Letzte Beiträge

Zufallselement beim Testen
05.08.2011 02:27
Gesellschaftliche Verantwortung
03.12.2010 11:33
mehrsprachig bloggen
26.06.2010 00:56

Letzte Kommentare

SO_REUSEADDR
22.04.2011 05:29
thanks
13.04.2011 11:37
SO_REUSEPORT for clients
08.02.2011 19:34

Archiv

  • [-]2011(1)
    • [-]August(1)
  • [-]2010(2)
    • [-]Dezember(1)
    • [-]Juni(1)

Meist gelesene Posts

mehrsprachig bloggen
88 times viewed
26.06.2010 00:56
Zufallselement beim Testen
50 times viewed
05.08.2011 02:27
Gesellschaftliche Verantwortung
33 times viewed
03.12.2010 11:33
bookmark at StumbleUpon
ⓒ Isidor Zeuner

April 2011
S M T W T F S
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30

Blog rolls