]> git.kaiwu.me - haproxy.git/commitdiff
MINOR: bwlim: Look up the bandwidth filter with the filter helpers
authorChristopher Faulet <cfaulet@haproxy.com>
Fri, 2 Oct 2026 16:06:21 +0000 (18:06 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 9 Oct 2026 14:17:36 +0000 (16:17 +0200)
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.

src/flt_bwlim.c

index d52b11f3f89714091e892512a43d6d9f5e786fe1..d163fcb2d56dbec42e1f4a0d22eacb1ee118e1ff 100644 (file)
@@ -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 <data>.
+ */
+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 <err> 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");