From: Christopher Faulet Date: Tue, 27 Oct 2026 10:50:33 +0000 (+0100) Subject: MINOR: bwlim: Stop to explicitly loop on the proxy's filter_configs list X-Git-Tag: v3.5-dev10~32 X-Git-Url: https://git.kaiwu.me/?a=commitdiff_plain;h=cb83a1898ea0c710ba9af87292a904f1929a0c31;p=haproxy.git MINOR: bwlim: Stop to explicitly loop on the proxy's filter_configs list The bandwidth limitation filter keyword parsers scanned the filter_configs list of the proxy by hand to detect an already declared "bwlim-in" or "bwlim-out" configuration, matching on the filter ids and the limitation name. The parsers now use flt_find_conf() with a match callback, the supported way to find a filter configuration, which walks the right list depending on the filter mode of the proxy. The duplicate check matches both filter ids at once, with a single lookup. --- diff --git a/src/flt_bwlim.c b/src/flt_bwlim.c index 6a2710007..acdcd75db 100644 --- a/src/flt_bwlim.c +++ b/src/flt_bwlim.c @@ -750,6 +750,16 @@ INITCALL1(STG_REGISTER, tcp_res_cont_keywords_register, &tcp_res_cont_actions); INITCALL1(STG_REGISTER, http_req_keywords_register, &http_req_actions); INITCALL1(STG_REGISTER, http_res_keywords_register, &http_res_actions); +static int bwlim_find_flt_by_name(struct flt_conf *fconf, void *data) +{ + if (fconf->id == bwlim_in_flt_id || fconf->id == bwlim_out_flt_id) { + struct bwlim_config *conf = fconf->conf; + const char *name = data; + + return (strcmp(name, conf->name) == 0); + } + return 0; +} /* Generic function to parse bandwidth limitation filter configurartion. It * Returns -1 on error and 0 on success. It handles configuration for per-stream @@ -758,7 +768,6 @@ INITCALL1(STG_REGISTER, http_res_keywords_register, &http_res_actions); static int parse_bwlim_flt(char **args, int *cur_arg, struct proxy *px, struct flt_conf *fconf, char **err, void *private) { - struct flt_conf *fc; struct bwlim_config *conf; int shared, per_stream; int pos = *cur_arg + 1; @@ -781,17 +790,12 @@ static int parse_bwlim_flt(char **args, int *cur_arg, struct proxy *px, struct f goto error; } - list_for_each_entry(fc, &px->filter_configs, list) { - if (fc->id == bwlim_in_flt_id || fc->id == bwlim_out_flt_id) { - struct bwlim_config *c = fc->conf; - - if (strcmp(conf->name, c->name) == 0) { - memprintf(err, "bwlim filter '%s' already declared for proxy '%s'\n", - conf->name, px->id); - goto error; - } - } + if (flt_find_conf(px, NULL, FLT_SIDE_GLOBAL, bwlim_find_flt_by_name, conf->name)) { + memprintf(err, "bwlim filter '%s' already declared for proxy '%s'\n", + conf->name, px->id); + goto error; } + shared = per_stream = 0; pos++; while (*args[pos]) {