]> git.kaiwu.me - haproxy.git/commitdiff
MINOR: bwlim: Use a different filter ID for in/out filters
authorChristopher Faulet <cfaulet@haproxy.com>
Thu, 24 Sep 2026 20:30:11 +0000 (22:30 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 9 Oct 2026 14:17:35 +0000 (16:17 +0200)
The in or out bandwidth limitation can be considered as two different kind
of filters. They rely on same functions but they are applied on different
channels. In addition, the filter keywords are already oriented. So it is
better to also use a different filter id.

src/flt_bwlim.c

index a7e7a2e831a25afff5891177fcb9f54430ee98f5..f94706423e5b00849946e37d81519cb66757db24 100644 (file)
@@ -26,7 +26,8 @@
 #include <haproxy/time.h>
 #include <haproxy/tools.h>
 
-const char *bwlim_flt_id = "bandwidth limitation filter";
+const char *bwlim_in_flt_id = "input bandwidth limitation filter";
+const char *bwlim_out_flt_id = "output bandwidth limitation filter";
 
 struct flt_ops bwlim_ops;
 
@@ -374,7 +375,11 @@ static enum act_return bwlim_set_limit(struct act_rule *rule, struct proxy *px,
        int opt;
 
        list_for_each_entry(filter, &s->strm_flt.filters, list) {
-               if (FLT_ID(filter) == bwlim_flt_id && FLT_CONF(filter) == conf) {
+               if (FLT_ID(filter) == bwlim_in_flt_id && FLT_CONF(filter) == conf) {
+                       st = filter->ctx;
+                       break;
+               }
+               if (FLT_ID(filter) == bwlim_out_flt_id && FLT_CONF(filter) == conf) {
                        st = filter->ctx;
                        break;
                }
@@ -453,7 +458,7 @@ int check_bwlim_action(struct act_rule *rule, struct proxy *px, char **err)
 
        list_for_each_entry(fconf, &px->filter_configs, list) {
                conf = NULL;
-               if (fconf->id == bwlim_flt_id) {
+               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;
@@ -760,7 +765,7 @@ static int parse_bwlim_flt(char **args, int *cur_arg, struct proxy *px, struct f
                memprintf(err, "'%s' : a name is expected as first argument ", args[*cur_arg]);
                goto error;
        }
-       conf->flags = BWLIM_FL_NONE;
+       conf->flags = ((fconf->id == bwlim_in_flt_id) ? BWLIM_FL_IN : BWLIM_FL_OUT);
        conf->name = strdup(args[pos]);
        if (!conf->name) {
                memprintf(err, "%s: out of memory", args[*cur_arg]);
@@ -768,7 +773,7 @@ static int parse_bwlim_flt(char **args, int *cur_arg, struct proxy *px, struct f
        }
 
        list_for_each_entry(fc, &px->filter_configs, list) {
-               if (fc->id == bwlim_flt_id) {
+               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) {
@@ -916,8 +921,6 @@ static int parse_bwlim_flt(char **args, int *cur_arg, struct proxy *px, struct f
                }
        }
        else {
-               /* Per-stream: limit downloads only for now */
-               conf->flags |= BWLIM_FL_OUT;
                if (!conf->period) {
                        memprintf(err, "'%s' : <default-period> option is missing", args[*cur_arg]);
                        goto error;
@@ -929,7 +932,7 @@ static int parse_bwlim_flt(char **args, int *cur_arg, struct proxy *px, struct f
        }
 
        *cur_arg = pos;
-       fconf->id   = bwlim_flt_id;
+       fconf->name = conf->name;
        fconf->ops  = &bwlim_ops;
        fconf->conf = conf;
        return 0;
@@ -951,30 +954,15 @@ static int parse_bwlim_flt(char **args, int *cur_arg, struct proxy *px, struct f
 static int parse_bwlim_in_flt(char **args, int *cur_arg, struct proxy *px, struct flt_conf *fconf,
                              char **err, void *private)
 {
-       int ret;
-
-       ret = parse_bwlim_flt(args, cur_arg, px, fconf, err, private);
-       if (!ret) {
-               struct bwlim_config *conf = fconf->conf;
-
-               conf->flags |= BWLIM_FL_IN;
-       }
-
-       return ret;
+       fconf->id = bwlim_in_flt_id;
+       return parse_bwlim_flt(args, cur_arg, px, fconf, err, private);
 }
 
 static int parse_bwlim_out_flt(char **args, int *cur_arg, struct proxy *px, struct flt_conf *fconf,
                               char **err, void *private)
 {
-       int ret;
-
-       ret = parse_bwlim_flt(args, cur_arg, px, fconf, err, private);
-       if (!ret) {
-               struct bwlim_config *conf = fconf->conf;
-
-               conf->flags |= BWLIM_FL_OUT;
-       }
-       return ret;
+       fconf->id = bwlim_out_flt_id;
+       return parse_bwlim_flt(args, cur_arg, px, fconf, err, private);
 }
 
 /* Declare the filter parser for "trace" keyword */