]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: cfgparse: parse tune.{rcvbuf,sndbuf}.{client,server} as sizes
authorWilly Tarreau <w@1wt.eu>
Mon, 18 Nov 2024 17:45:45 +0000 (18:45 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 18 Nov 2024 17:49:01 +0000 (18:49 +0100)
Till now these values were parsed as raw integer using atol() and would
silently ignore any trailing suffix, causing unexpected behaviors when
set, e.g. to "512k". Let's make use of parse_size_err() on them so that
units are supported. This requires to turn them to uint as well, which
is OK.

doc/configuration.txt
include/haproxy/global-t.h
src/cfgparse-global.c

index 5cfdb2ee37cb8591f0447bb45ffd71748a3f8a93..9f38da615171420f4b2847211240104a8d3bc1c7 100644 (file)
@@ -4101,8 +4101,8 @@ tune.rcvbuf.frontend <number>
   counter parts, as well as "tune.sndbuf.backend" and "tune.sndbuf.frontend"
   for the send setting.
 
-tune.rcvbuf.client <number>
-tune.rcvbuf.server <number>
+tune.rcvbuf.client <size>
+tune.rcvbuf.server <size>
   Forces the kernel socket receive buffer size on the client or the server side
   to the specified value in bytes. This value applies to all TCP/HTTP frontends
   and backends. It should normally never be set, and the default size (0) lets
@@ -4164,8 +4164,8 @@ tune.sndbuf.frontend <number>
   "tune.sndbuf.server" for their connected socket counter parts, as well as
   "tune.rcvbuf.backend" and "tune.rcvbuf.frontend" for the receive setting.
 
-tune.sndbuf.client <number>
-tune.sndbuf.server <number>
+tune.sndbuf.client <size>
+tune.sndbuf.server <size>
   Forces the kernel socket send buffer size on the client or the server side to
   the specified value in bytes. This value applies to all TCP/HTTP frontends
   and backends. It should normally never be set, and the default size (0) lets
index 4e41860ef1dc13d59205e4dfc74430145d01d595..3cf3f09a7544af6de48677ee81ec0f5fb4ca1be9 100644 (file)
@@ -170,10 +170,10 @@ struct global {
                int maxrewrite;    /* buffer max rewrite size in bytes, defaults to MAXREWRITE */
                int reserved_bufs; /* how many buffers can only be allocated for response */
                int buf_limit;     /* if not null, how many total buffers may only be allocated */
-               int client_sndbuf; /* set client sndbuf to this value if not null */
-               int client_rcvbuf; /* set client rcvbuf to this value if not null */
-               int server_sndbuf; /* set server sndbuf to this value if not null */
-               int server_rcvbuf; /* set server rcvbuf to this value if not null */
+               uint client_sndbuf;   /* set client sndbuf to this value if not null */
+               uint client_rcvbuf;   /* set client rcvbuf to this value if not null */
+               uint server_sndbuf;   /* set server sndbuf to this value if not null */
+               uint server_rcvbuf;   /* set server rcvbuf to this value if not null */
                int frontend_sndbuf; /* set frontend dgram sndbuf to this value if not null */
                int frontend_rcvbuf; /* set frontend dgram rcvbuf to this value if not null */
                int backend_sndbuf;  /* set backend dgram sndbuf to this value if not null */
index 93ed4521758dc23e4320887059ce328052c99f5a..77f2e0f61375908c15a56e2e4703d5054070ceab 100644 (file)
@@ -1121,6 +1121,7 @@ static int cfg_parse_global_tune_opts(char **args, int section_type,
                                      struct proxy *curpx, const struct proxy *defpx,
                                      const char *file, int line, char **err)
 {
+       const char *res;
 
        if (too_many_args(1, args, err, NULL))
                return -1;
@@ -1212,8 +1213,6 @@ static int cfg_parse_global_tune_opts(char **args, int section_type,
        }
        else if (strcmp(args[0], "tune.idletimer") == 0) {
                unsigned int idle;
-               const char *res;
-
 
                if (*(args[1]) == 0) {
                        memprintf(err, "'%s' expects a timer value between 0 and 65535 ms.", args[0]);
@@ -1253,7 +1252,9 @@ static int cfg_parse_global_tune_opts(char **args, int section_type,
                        memprintf(err, "'%s' expects an integer argument.", args[0]);
                        return -1;
                }
-               global.tune.client_rcvbuf = atol(args[1]);
+               res = parse_size_err(args[1], &global.tune.client_rcvbuf);
+               if (res != NULL)
+                       goto size_err;
 
                return 0;
        }
@@ -1266,7 +1267,9 @@ static int cfg_parse_global_tune_opts(char **args, int section_type,
                        memprintf(err, "'%s' expects an integer argument.", args[0]);
                        return -1;
                }
-               global.tune.server_rcvbuf = atol(args[1]);
+               res = parse_size_err(args[1], &global.tune.server_rcvbuf);
+               if (res != NULL)
+                       goto size_err;
 
                return 0;
        }
@@ -1279,7 +1282,9 @@ static int cfg_parse_global_tune_opts(char **args, int section_type,
                        memprintf(err, "'%s' expects an integer argument.", args[0]);
                        return -1;
                }
-               global.tune.client_sndbuf = atol(args[1]);
+               res = parse_size_err(args[1], &global.tune.client_sndbuf);
+               if (res != NULL)
+                       goto size_err;
 
                return 0;
        }
@@ -1292,7 +1297,9 @@ static int cfg_parse_global_tune_opts(char **args, int section_type,
                        memprintf(err, "'%s' expects an integer argument.", args[0]);
                        return -1;
                }
-               global.tune.server_sndbuf = atol(args[1]);
+               res = parse_size_err(args[1], &global.tune.server_sndbuf);
+               if (res != NULL)
+                       goto size_err;
 
                return 0;
        }
@@ -1366,6 +1373,11 @@ static int cfg_parse_global_tune_opts(char **args, int section_type,
        }
 
        return 0;
+
+ size_err:
+       memprintf(err, "unexpected '%s' after size passed to '%s'", res, args[0]);
+       return -1;
+
 }
 
 static int cfg_parse_global_tune_forward_opts(char **args, int section_type,