From a6504c9cfb6bb48ae93babb76a2ab10ddb014a79 Mon Sep 17 00:00:00 2001 From: Amaury Denoyelle Date: Tue, 19 Nov 2024 10:12:27 +0100 Subject: [PATCH] MINOR: quic: use dynamic cc_algo on bind_conf A QUIC congestion algorithm can be specified on the bind line via keyword quic-cc-algo. As such, bind_conf structure has a member quic_cc_algo. Previously, if quic-cc-algo was set, bind_conf member was initialized to one of the globally defined CC algo structure. This patch changes bind_conf quic_cc_algo initialization to point to a dynamically allocated copy of CC algo structure. With this change, it will be possible to tweak individually each CC algo of a bind line. This will be used to activate pacing on top of the congestion algorithm. As bind_conf member is dynamically allocated now, its member is now freed via free_proxy() to prevent any leak. --- src/cfgparse-quic.c | 15 +++++++++++---- src/proxy.c | 3 +++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/cfgparse-quic.c b/src/cfgparse-quic.c index a33c05e23..7d870625b 100644 --- a/src/cfgparse-quic.c +++ b/src/cfgparse-quic.c @@ -73,10 +73,16 @@ static unsigned long parse_window_size(const char *kw, char *value, static int bind_parse_quic_cc_algo(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err) { - struct quic_cc_algo *cc_algo; + struct quic_cc_algo *cc_algo = NULL; const char *algo = NULL; char *arg; + cc_algo = calloc(1, sizeof(struct quic_cc_algo)); + if (!cc_algo) { + memprintf(err, "'%s' : out of memory", args[cur_arg]); + goto fail; + } + if (!*args[cur_arg + 1]) { memprintf(err, "'%s' : missing control congestion algorithm", args[cur_arg]); goto fail; @@ -86,13 +92,13 @@ static int bind_parse_quic_cc_algo(char **args, int cur_arg, struct proxy *px, if (strncmp(arg, QUIC_CC_NEWRENO_STR, strlen(QUIC_CC_NEWRENO_STR)) == 0) { /* newreno */ algo = QUIC_CC_NEWRENO_STR; - cc_algo = &quic_cc_algo_nr; + *cc_algo = quic_cc_algo_nr; arg += strlen(QUIC_CC_NEWRENO_STR); } else if (strncmp(arg, QUIC_CC_CUBIC_STR, strlen(QUIC_CC_CUBIC_STR)) == 0) { /* cubic */ algo = QUIC_CC_CUBIC_STR; - cc_algo = &quic_cc_algo_cubic; + *cc_algo = quic_cc_algo_cubic; arg += strlen(QUIC_CC_CUBIC_STR); } else if (strncmp(arg, QUIC_CC_NO_CC_STR, strlen(QUIC_CC_NO_CC_STR)) == 0) { @@ -104,7 +110,7 @@ static int bind_parse_quic_cc_algo(char **args, int cur_arg, struct proxy *px, } algo = QUIC_CC_NO_CC_STR; - cc_algo = &quic_cc_algo_nocc; + *cc_algo = quic_cc_algo_nocc; arg += strlen(QUIC_CC_NO_CC_STR); } else { @@ -132,6 +138,7 @@ static int bind_parse_quic_cc_algo(char **args, int cur_arg, struct proxy *px, return 0; fail: + free(cc_algo); return ERR_ALERT | ERR_FATAL; } diff --git a/src/proxy.c b/src/proxy.c index 357704209..d968e7579 100644 --- a/src/proxy.c +++ b/src/proxy.c @@ -387,6 +387,9 @@ void free_proxy(struct proxy *p) LIST_DELETE(&bind_conf->by_fe); free(bind_conf->guid_prefix); free(bind_conf->rhttp_srvname); +#ifdef USE_QUIC + free(bind_conf->quic_cc_algo); +#endif free(bind_conf); }