]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
socket-proxyd: Introduced dynamic connection limit via an option. (#4749)
author(GalaxyMaster) <galaxy4public@users.noreply.github.com>
Mon, 28 Nov 2016 17:25:11 +0000 (04:25 +1100)
committerLennart Poettering <lennart@poettering.net>
Mon, 28 Nov 2016 17:25:11 +0000 (18:25 +0100)
man/systemd-socket-proxyd.xml
src/socket-proxy/socket-proxyd.c

index ae4217b910eb079b89d92af95fa3d6be73a78f36..804a8c38f17b33ae7cd9831563b72ba4be684ec8 100644 (file)
     <variablelist>
       <xi:include href="standard-options.xml" xpointer="help" />
       <xi:include href="standard-options.xml" xpointer="version" />
+      <varlistentry>
+        <term><option>--max-connections=</option></term>
+        <term><option>-c</option></term>
+
+        <listitem><para>Sets the maximum number of simultaneous connections, defaults to 256.
+        If the limit of concurrent connections is reached further connections will be refused.</para></listitem>
+      </varlistentry>
     </variablelist>
   </refsect1>
   <refsect1>
index 52b4db8875fb2de71dab07cd3153b8b7b5fb28f6..b810891d7d24bdbd324daa2a58e2edabb7d653b6 100644 (file)
 #include "set.h"
 #include "socket-util.h"
 #include "string-util.h"
+#include "parse-util.h"
 #include "util.h"
 
 #define BUFFER_SIZE (256 * 1024)
-#define CONNECTIONS_MAX 256
+static unsigned arg_connections_max = 256;
 
 static const char *arg_remote_host = NULL;
 
@@ -445,7 +446,7 @@ static int add_connection_socket(Context *context, int fd) {
         assert(context);
         assert(fd >= 0);
 
-        if (set_size(context->connections) > CONNECTIONS_MAX) {
+        if (set_size(context->connections) > arg_connections_max) {
                 log_warning("Hit connection limit, refusing connection.");
                 safe_close(fd);
                 return 0;
@@ -563,6 +564,7 @@ static void help(void) {
         printf("%1$s [HOST:PORT]\n"
                "%1$s [SOCKET]\n\n"
                "Bidirectionally proxy local sockets to another (possibly remote) socket.\n\n"
+               "  -c --max-connections=  Set the maximum number of connections to be accepted\n"
                "  -h --help              Show this help\n"
                "     --version           Show package version\n",
                program_invocation_short_name);
@@ -576,17 +578,18 @@ static int parse_argv(int argc, char *argv[]) {
         };
 
         static const struct option options[] = {
-                { "help",       no_argument, NULL, 'h'           },
-                { "version",    no_argument, NULL, ARG_VERSION   },
+                { "connections-max", required_argument, NULL, 'c'           },
+                { "help",            no_argument,       NULL, 'h'           },
+                { "version",         no_argument,       NULL, ARG_VERSION   },
                 {}
         };
 
-        int c;
+        int c, r;
 
         assert(argc >= 0);
         assert(argv);
 
-        while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0)
+        while ((c = getopt_long(argc, argv, "c:h", options, NULL)) >= 0)
 
                 switch (c) {
 
@@ -594,6 +597,20 @@ static int parse_argv(int argc, char *argv[]) {
                         help();
                         return 0;
 
+                case 'c':
+                        r = safe_atou(optarg, &arg_connections_max);
+                        if (r < 0) {
+                                log_error("Failed to parse --connections-max= argument: %s", optarg);
+                                return r;
+                        }
+
+                        if (arg_connections_max < 1) {
+                                log_error("Connection limit is too low.");
+                                return -EINVAL;
+                        }
+
+                        break;
+
                 case ARG_VERSION:
                         return version();