MINOR: quic: extract config window-size parsing

quic-cc-algo is a bind line keyword which allow to select a QUIC
congestion algorithm. It can take an optional integer to specify the
maximum window size. This value is an integer and support the suffixes
'k', 'm' and 'g' to specify respectively kilobytes, megabytes and
gigabytes.

Extract the maximum window size parsing in a dedicated function named
parse_window_size(). It accepts as input an integer value with an
optional suffix, 'k', 'm' or 'g'. The first invalid character is
returned by the function to the caller.

No functional change. This commit will allow to quickly implement a new
keyword to configure a default congestion window size in the global
section.
This commit is contained in:
Amaury Denoyelle 2024-08-14 18:30:34 +02:00
parent 5b6e8c4d4d
commit 280b61468a

View File

@ -25,6 +25,48 @@ static int bind_parse_quic_force_retry(char **args, int cur_arg, struct proxy *p
return 0;
}
/* Parse <value> as a window size integer argument to keyword <kw>. By
* default, value is explained as bytes. Suffixes 'k', 'm' and 'g' are valid as
* multipliers. <end_opt> will point to the next unparsed character.
*
* Return the parsed window size or 0 on error.
*/
static unsigned long parse_window_size(const char *kw, char *value,
char **end_opt, char **err)
{
unsigned long size;
errno = 0;
size = strtoul(value, end_opt, 0);
if (*end_opt == value || errno != 0) {
memprintf(err, "'%s' : could not parse congestion window value", kw);
goto fail;
}
if (**end_opt == 'k') {
size <<= 10;
(*end_opt)++;
}
else if (**end_opt == 'm') {
size <<= 20;
(*end_opt)++;
}
else if (**end_opt == 'g') {
size <<= 30;
(*end_opt)++;
}
if (size < 10240 || size > (4UL << 30)) {
memprintf(err, "'%s' : should be between 10k and 4g", kw);
goto fail;
}
return size;
fail:
return 0;
}
/* parse "quic-cc-algo" bind keyword */
static int bind_parse_quic_cc_algo(char **args, int cur_arg, struct proxy *px,
struct bind_conf *conf, char **err)
@ -72,36 +114,15 @@ static int bind_parse_quic_cc_algo(char **args, int cur_arg, struct proxy *px,
unsigned long cwnd;
char *end_opt;
errno = 0;
cwnd = strtoul(arg, &end_opt, 0);
if (end_opt == arg || errno != 0) {
memprintf(err, "'%s' : could not parse congestion window value", args[cur_arg + 1]);
cwnd = parse_window_size(args[cur_arg], arg, &end_opt, err);
if (!cwnd)
goto fail;
}
if (*end_opt == 'k') {
cwnd <<= 10;
end_opt++;
}
else if (*end_opt == 'm') {
cwnd <<= 20;
end_opt++;
}
else if (*end_opt == 'g') {
cwnd <<= 30;
end_opt++;
}
if (*end_opt != ')') {
memprintf(err, "'%s' : expects %s(<max window>)", args[cur_arg + 1], algo);
goto fail;
}
if (cwnd < 10240 || cwnd > (4UL << 30)) {
memprintf(err, "'%s' : should be greater than 10k and smaller than 4g", args[cur_arg + 1]);
goto fail;
}
conf->max_cwnd = cwnd;
}