MINOR: cfgparse: parse tune.{rcvbuf,sndbuf}.{client,server} as sizes

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.
This commit is contained in:
Willy Tarreau 2024-11-18 18:45:45 +01:00
parent 45f9e95f22
commit a923c72357
3 changed files with 26 additions and 14 deletions

View 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

View 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 */

View 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,