From: Christopher Faulet Date: Fri, 2 Oct 2026 16:06:21 +0000 (+0200) Subject: MINOR: bwlim: Look up the bandwidth filter with the filter helpers X-Git-Tag: v3.5-dev9~68 X-Git-Url: https://git.kaiwu.me/$%7BISSUES%7D/static/gitweb.js?a=commitdiff_plain;h=ed744bc07b2e92e7343e472f5b8e4d71a9cc5e35;p=haproxy.git MINOR: bwlim: Look up the bandwidth filter with the filter helpers Resolve the set-bandwidth-limit filter with flt_find_conf() and a match callback on the bandwidth limitation class and the filter name. This works with both the legacy configurations and the filter instances, and it fixes the lookup that could return a non-matching bandwidth filter when no filter matched. --- diff --git a/src/flt_bwlim.c b/src/flt_bwlim.c index d52b11f3f..d163fcb2d 100644 --- a/src/flt_bwlim.c +++ b/src/flt_bwlim.c @@ -449,6 +449,20 @@ static enum act_return bwlim_set_limit(struct act_rule *rule, struct proxy *px, return ACT_RET_CONT; } +/* Match callback for flt_find_conf() in check_bwlim_action(): matches the + * bwlim filter configurations with the name . + */ +static int bwlim_find_flt(struct flt_conf *fconf, void *data) +{ + struct bwlim_config *conf; + const char *name = data; + + if (fconf->id != bwlim_in_flt_id && fconf->id != bwlim_out_flt_id) + return 0; + conf = fconf->conf; + return (conf && strcmp(name, conf->name) == 0); +} + /* Check function for "set-bandwidth-limit" action. It returns 1 on * success. Otherwise, it returns 0 and is filled. */ @@ -458,19 +472,13 @@ int check_bwlim_action(struct act_rule *rule, struct proxy *px, char **err) struct bwlim_config *conf = NULL; unsigned int where; - list_for_each_entry(fconf, &px->filter_configs, list) { - conf = NULL; - if (fconf->id == bwlim_in_flt_id || fconf->id == bwlim_out_flt_id) { - conf = fconf->conf; - if (strcmp(rule->arg.act.p[0], conf->name) == 0) - break; - } - } - if (!conf) { + fconf = flt_find_conf(px, NULL, FLT_SIDE_GLOBAL, bwlim_find_flt, rule->arg.act.p[0]); + if (!fconf) { memprintf(err, "unable to find bwlim filter '%s' referenced by set-bandwidth-limit rule", (char *)rule->arg.act.p[0]); return 0; } + conf = fconf->conf; if ((conf->flags & BWLIM_FL_SHARED) && rule->arg.act.p[1]) { memprintf(err, "set-bandwidth-limit rule cannot define a limit for a shared bwlim filter");