From 280b61468a75b40d710a07ff232f69e5a9b42339 Mon Sep 17 00:00:00 2001 From: Amaury Denoyelle Date: Wed, 14 Aug 2024 18:30:34 +0200 Subject: [PATCH] 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. --- src/cfgparse-quic.c | 67 +++++++++++++++++++++++++++++---------------- 1 file changed, 44 insertions(+), 23 deletions(-) diff --git a/src/cfgparse-quic.c b/src/cfgparse-quic.c index 413d136c4f..85e5d294fc 100644 --- a/src/cfgparse-quic.c +++ b/src/cfgparse-quic.c @@ -25,6 +25,48 @@ static int bind_parse_quic_force_retry(char **args, int cur_arg, struct proxy *p return 0; } +/* Parse as a window size integer argument to keyword . By + * default, value is explained as bytes. Suffixes 'k', 'm' and 'g' are valid as + * multipliers. 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()", 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; } -- 2.47.3