From: Christopher Faulet Date: Tue, 27 Oct 2026 13:07:10 +0000 (+0100) Subject: MINOR: filters: Add a function to find a legacy filter configuration during parsing X-Git-Tag: v3.5-dev10~35 X-Git-Url: https://git.kaiwu.me/?a=commitdiff_plain;h=da9a0781ce4bd8b11a1ce6c8e3783d27b8bf2a37;p=haproxy.git MINOR: filters: Add a function to find a legacy filter configuration during parsing flt_find_conf() resolves a filter configuration through the filter mode of the proxy: from the filter instances in the new mode, from the legacy configurations otherwise. A directive parsing its own configuration during the configuration parsing cannot use it: the mode of the proxy is not known yet, it is deduced later from the implied filters, and in the new mode the legacy configurations of the filters that registered no class are ignored after the post-parsing stage. flt_find_legacy_conf() is the parsing-time counterpart of flt_find_conf(): it always searches the legacy filter configurations of the proxy, in declaration order, whatever the filter mode. Like flt_find_conf(), it filters the candidates by filter id, with an optional match callback. It must only be used during the configuration parsing, before the mode is deduced: the check callbacks of the rules keep resolving their configuration with flt_find_conf(), once the instances were finalized. --- diff --git a/include/haproxy/filters.h b/include/haproxy/filters.h index 9f4ffa118..b9e27e434 100644 --- a/include/haproxy/filters.h +++ b/include/haproxy/filters.h @@ -167,6 +167,8 @@ int flt_foreach_conf(struct proxy *px, unsigned int side, int (*fct)(struct flt_conf *fconf, void *data), void *data); struct flt_conf *flt_find_conf(struct proxy *px, const char *flt_id, unsigned int side, int (*match)(struct flt_conf *fconf, void *data), void *data); +struct flt_conf *flt_find_legacy_conf(struct proxy *px, const char *flt_id, + int (*match)(struct flt_conf *fconf, void *data), void *data); int flt_stream_start(struct stream *s); void flt_stream_stop(struct stream *s); diff --git a/src/filters.c b/src/filters.c index c9e453719..e4994ff0f 100644 --- a/src/filters.c +++ b/src/filters.c @@ -2145,6 +2145,32 @@ struct flt_conf *flt_find_conf(struct proxy *px, const char *flt_id, unsigned in return ctx.found; } +/* Finds a legacy filter configuration of the proxy with the id + * (any id if NULL), searching the legacy configurations in + * declaration order, whatever the filter mode of the proxy. Unlike + * flt_find_conf(), it never resolves the configurations of the filter + * instances, so it must only be used during the configuration parsing, + * before the mode of the proxy is deduced: after the post-parsing stage, + * the legacy configurations of the filters that registered no class are + * ignored in the new mode. If is not NULL, it is called with each + * candidate and and must return non-zero to accept it. Returns the + * first match, or NULL if none. + */ +struct flt_conf *flt_find_legacy_conf(struct proxy *px, const char *flt_id, + int (*match)(struct flt_conf *fconf, void *data), void *data) +{ + struct flt_conf *fconf; + + list_for_each_entry(fconf, &px->filter_configs, list) { + if (flt_id && fconf->id != flt_id) + continue; + if (match && !match(fconf, data)) + continue; + return fconf; + } + return NULL; +} + /* Links in the global class references of and on each side its * class is placed on. All links were initialized on allocation.