[systemd-devel] [PATCH] Allow selection of TCP Congestion Avoidance algorithm to socket

Tomasz Torcz tomek at pipebreaker.pl
Tue Aug 3 04:33:40 PDT 2010


Hi,

  attached path extends socket configurables with another
knob - TCP Congestion Avoidance selection. Linux implements
handful of those, useful in various situations. For example,
TCP Low Priority may be used by FTP service to gracefully
yield bandwidth for more important TCP/IP streams.
  Until recently TCP_CONGESTION was Linux-specific, recently
FreeBSD 8 and OpenSolaris gained compatible support.


-- 
Tomasz Torcz                 "God, root, what's the difference?"
xmpp: zdzichubg at chrome.pl         "God is more forgiving."

-------------- next part --------------
From 14d55d667d8864fceecc15eea10d511f38e86cee Mon Sep 17 00:00:00 2001
From: Tomasz Torcz <tomek at pipebreaker.pl>
Date: Tue, 3 Aug 2010 11:47:17 +0200
Subject: [PATCH] socket: allow selection of TCP Congestion Avoidance algorithm

---
 man/systemd.socket.xml |    9 +++++++++
 src/load-fragment.c    |    1 +
 src/socket.c           |   12 +++++++++++-
 src/socket.h           |    1 +
 4 files changed, 22 insertions(+), 1 deletions(-)

diff --git a/man/systemd.socket.xml b/man/systemd.socket.xml
index 20dc00e..f445ad1 100644
--- a/man/systemd.socket.xml
+++ b/man/systemd.socket.xml
@@ -438,6 +438,15 @@
                         </varlistentry>
 
                         <varlistentry>
+                                <term><varname>TCPCongestion=</varname></term>
+                                <listitem><para>Takes a string
+                                value. Controls TCP congestion algorithm
+                                used by this socket. Should be one
+                                of "westwood", "veno", "cubic", "lp" or
+                                any other available algorithm.
+                                This setting matters only for stream socket.</para></listitem>
+
+                        <varlistentry>
                                 <term><varname>ExecStartPre=</varname></term>
                                 <term><varname>ExecStartPost=</varname></term>
                                 <listitem><para>Takes one or more
diff --git a/src/load-fragment.c b/src/load-fragment.c
index 98f16f9..f2f2d72 100644
--- a/src/load-fragment.c
+++ b/src/load-fragment.c
@@ -1616,6 +1616,7 @@ static int load_from_path(Unit *u, const char *path) {
                 { "Mark",                   config_parse_int,             &u->socket.mark,                                 "Socket"  },
                 { "PipeSize",               config_parse_size,            &u->socket.pipe_size,                            "Socket"  },
                 { "FreeBind",               config_parse_bool,            &u->socket.free_bind,                            "Socket"  },
+                { "TCPCongestion",          config_parse_string,          &u->socket.tcp_congestion,                       "Socket"  },
                 EXEC_CONTEXT_CONFIG_ITEMS(u->socket.exec_context, "Socket"),
 
                 { "What",                   config_parse_string,          &u->mount.parameters_fragment.what,              "Mount"   },
diff --git a/src/socket.c b/src/socket.c
index 82a9348..c7573d2 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -31,6 +31,7 @@
 
 #include "unit.h"
 #include "socket.h"
+#include "netinet/tcp.h"
 #include "log.h"
 #include "load-dropin.h"
 #include "load-fragment.h"
@@ -73,6 +74,7 @@ static void socket_init(Unit *u) {
         s->ip_tos = -1;
         s->ip_ttl = -1;
         s->mark = -1;
+        s->tcp_congestion = NULL;
 
         exec_context_init(&s->exec_context);
 
@@ -372,13 +374,15 @@ static void socket_dump(Unit *u, FILE *f, const char *prefix) {
                 "%sDirectoryMode: %04o\n"
                 "%sKeepAlive: %s\n"
                 "%sFreeBind: %s\n",
+                "%sTCPCongestion: %s\n",
                 prefix, socket_state_to_string(s->state),
                 prefix, socket_address_bind_ipv6_only_to_string(s->bind_ipv6_only),
                 prefix, s->backlog,
                 prefix, s->socket_mode,
                 prefix, s->directory_mode,
                 prefix, yes_no(s->keep_alive),
-                prefix, yes_no(s->free_bind));
+                prefix, yes_no(s->free_bind),
+                prefix, s->tcp_congestion);
 
         if (s->control_pid > 0)
                 fprintf(f,
@@ -632,6 +636,12 @@ static void socket_apply_socket_options(Socket *s, int fd) {
                 if (r < 0 && x < 0)
                         log_warning("IP_TTL/IPV6_UNICAST_HOPS failed: %m");
         }
+
+        if (s->tcp_congestion)
+                if (setsockopt(fd, SOL_TCP, TCP_CONGESTION, s->tcp_congestion, strlen(s->tcp_congestion)+1) < 0)
+                        log_warning("TCP_CONGESTION failed: %m");
+
+
 }
 
 static void socket_apply_fifo_options(Socket *s, int fd) {
diff --git a/src/socket.h b/src/socket.h
index 88ebf26..230dd20 100644
--- a/src/socket.h
+++ b/src/socket.h
@@ -114,6 +114,7 @@ struct Socket {
         int mark;
         bool free_bind;
         char *bind_to_device;
+        char *tcp_congestion;
 
         /* Only for INET6 sockets: issue IPV6_V6ONLY sockopt */
         SocketAddressBindIPv6Only bind_ipv6_only;
-- 
1.7.2

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 238 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/systemd-devel/attachments/20100803/44506dbe/attachment.pgp>


More information about the systemd-devel mailing list