chiark / gitweb /
basic SO_REUSEPORT support
authorShawn Landden <shawnlandden@gmail.com>
Mon, 8 Jul 2013 18:28:14 +0000 (18:28 +0000)
committerLennart Poettering <lennart@poettering.net>
Thu, 11 Jul 2013 01:09:18 +0000 (03:09 +0200)
man/systemd.socket.xml
src/core/dbus-socket.c
src/core/socket.c
src/core/socket.h
src/shared/missing.h

index 0a2d86996be29c9001416b1e861dcee67f68a7a0..2e1fb7cea1654131ede13f6a1159a91fcfeffbff 100644 (file)
                                 for details.</para></listitem>
                         </varlistentry>
 
+                        <varlistentry>
+                                <term><varname>ReusePort=</varname></term>
+                                <listitem><para>Takes a boolean
+                                value. If true allows multiple bind()s
+                                to this TCP or UDP port.  This
+                                controls the SO_REUSEPORT socket
+                                option.  See
+                                <citerefentry><refentrytitle>socket</refentrytitle><manvolnum>7</manvolnum></citerefentry>
+                                for details.</para></listitem>
+                        </varlistentry>
+
                         <varlistentry>
                                 <term><varname>SmackLabel=</varname></term>
                                 <term><varname>SmackLabelIPIn=</varname></term>
index da317edb86d38c3c640ce922d0e5847813562e24..30c4b6302c3f0dd07077c5213cec4f8b124248a6 100644 (file)
@@ -67,6 +67,7 @@
         "  <property name=\"MessageQueueMessageSize\" type=\"x\" access=\"read\"/>\n" \
         "  <property name=\"Listen\" type=\"a(ss)\" access=\"read\"/>\n"    \
         "  <property name=\"Result\" type=\"s\" access=\"read\"/>\n"    \
+        "  <property name=\"ReusePort\" type=\"b\" access=\"read\"/>\n" \
         "  <property name=\"SmackLabel\" type=\"s\" access=\"read\"/>\n" \
         "  <property name=\"SmackLabelIPIn\" type=\"s\" access=\"read\"/>\n" \
         "  <property name=\"SmackLabelIPOut\" type=\"s\" access=\"read\"/>\n" \
@@ -194,6 +195,7 @@ static const BusProperty bus_socket_properties[] = {
         { "MessageQueueMaxMessages", bus_property_append_long, "x", offsetof(Socket, mq_maxmsg)       },
         { "MessageQueueMessageSize", bus_property_append_long, "x", offsetof(Socket, mq_msgsize)      },
         { "Result",         bus_socket_append_socket_result,   "s", offsetof(Socket, result)          },
+        { "ReusePort",      bus_property_append_bool,          "b", offsetof(Socket, reuseport)       },
         { "SmackLabel",     bus_property_append_string,        "s", offsetof(Socket, smack),          true },
         { "SmackLabelIPIn", bus_property_append_string,        "s", offsetof(Socket, smack_ip_in),    true },
         { "SmackLabelIPOut",bus_property_append_string,        "s", offsetof(Socket, smack_ip_out),   true },
index 2def0c9eadad80dfeb21ba52321aafc155b1d253..cf88bae9da32147b86f570ffb4f89241ade14d53 100644 (file)
@@ -536,6 +536,11 @@ static void socket_dump(Unit *u, FILE *f, const char *prefix) {
                         "%sMessageQueueMessageSize: %li\n",
                         prefix, s->mq_msgsize);
 
+        if (s->reuseport)
+                fprintf(f,
+                        "%sReusePort: %s\n",
+                         prefix, yes_no(s->reuseport));
+
         if (s->smack)
                 fprintf(f,
                         "%sSmackLabel: %s\n",
@@ -792,6 +797,12 @@ static void socket_apply_socket_options(Socket *s, int fd) {
                 if (setsockopt(fd, SOL_TCP, TCP_CONGESTION, s->tcp_congestion, strlen(s->tcp_congestion)+1) < 0)
                         log_warning_unit(UNIT(s)->id, "TCP_CONGESTION failed: %m");
 
+        if (s->reuseport) {
+                int b = s->reuseport;
+                if (setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &b, sizeof(b)))
+                        log_warning_unit(UNIT(s)->id, "SO_REUSEPORT failed: %m");
+        }
+
 #ifdef HAVE_SMACK
         if (s->smack_ip_in)
                 if (fsetxattr(fd, "security.SMACK64IPIN", s->smack_ip_in, strlen(s->smack_ip_in), 0) < 0)
index 15942c1c90f1897385a7e226b70f40330c706da6..8f9dfdbfb0f8c58300a3b7713320d834e207d59d 100644 (file)
@@ -144,6 +144,7 @@ struct Socket {
         size_t pipe_size;
         char *bind_to_device;
         char *tcp_congestion;
+        bool reuseport;
         long mq_maxmsg;
         long mq_msgsize;
 
index 24a8392b222ce4d45f37a10c2c7cc7b046d87efa..534b3ccd4e71f46efb675ffb68137462aa33ff0f 100644 (file)
@@ -266,3 +266,7 @@ static inline int name_to_handle_at(int fd, const char *name, struct file_handle
 #ifndef TFD_TIMER_CANCEL_ON_SET
 #define TFD_TIMER_CANCEL_ON_SET (1 << 1)
 #endif
+
+#ifndef SO_REUSEPORT
+#define SO_REUSEPORT 15
+#endif