From: Christopher Faulet Date: Fri, 2 Oct 2026 16:05:46 +0000 (+0200) Subject: MINOR: filters: Add flt_has_filter() and use it in proxy_finalize() X-Git-Tag: v3.5-dev9~74 X-Git-Url: https://git.kaiwu.me/?a=commitdiff_plain;h=319f83816b8186e047a2591cb94bcadcf5a52fd0;p=haproxy.git MINOR: filters: Add flt_has_filter() and use it in proxy_finalize() Add flt_has_filter() returning whether a proxy has at least one filter, from the legacy configurations or from the flattened instances. Use it in proxy_finalize() instead of testing px->filter_configs directly, so the filter analyzers are also enabled for proxies using the filter instances. proxy_finalize() runs after the filter instances are flattened, so the helper can safely inspect px->filter_instances. --- diff --git a/include/haproxy/filters.h b/include/haproxy/filters.h index ea68a6bec..680d51722 100644 --- a/include/haproxy/filters.h +++ b/include/haproxy/filters.h @@ -189,6 +189,8 @@ struct flt_kw *flt_find_kw(const char *kw); void flt_dump_kws(char **out); void list_filters(FILE *out); +int flt_has_filter(const struct proxy *px); + /* Returns != 0 if the proxy is in legacy filter mode, so when an explicit * legacy "filter" directive was used (PR_FL_FILTER_LEGACY). In legacy mode, the * filter configurations are in px->filter_configs; otherwise they come from the diff --git a/src/filters.c b/src/filters.c index 482a2bae5..7e344106f 100644 --- a/src/filters.c +++ b/src/filters.c @@ -406,6 +406,14 @@ list_filters(FILE *out) free(filters); } +/* Returns 1 if the proxy has at least one active filter, legacy or + * not. Must be called after the class references are flattened. + */ +int flt_has_filter(const struct proxy *px) +{ + return (!LIST_ISEMPTY(&px->filter_configs) || !LIST_ISEMPTY(&px->filter_instances)); +} + /* Checks for explicit filter instances or enable/sequence directives during * configuration parsing, before the class references are flattened. Inherited * directives count too, but implicit instances do not select a config mode. diff --git a/src/proxy.c b/src/proxy.c index a4e3af78e..c7a6688ad 100644 --- a/src/proxy.c +++ b/src/proxy.c @@ -2826,7 +2826,7 @@ int proxy_finalize(struct proxy *px, int *err_code) px->fe_req_ana |= AN_REQ_SWITCHING_RULES; /* Add filters analyzers if needed */ - if (!LIST_ISEMPTY(&px->filter_configs)) { + if (flt_has_filter(px)) { px->fe_req_ana |= AN_REQ_FLT_START_FE | AN_REQ_FLT_XFER_DATA | AN_REQ_FLT_END; px->fe_rsp_ana |= AN_RES_FLT_START_FE | AN_RES_FLT_XFER_DATA | AN_RES_FLT_END; } @@ -2853,7 +2853,7 @@ int proxy_finalize(struct proxy *px, int *err_code) px->be_req_ana |= AN_REQ_PRST_RDP_COOKIE; /* Add filters analyzers if needed */ - if (!LIST_ISEMPTY(&px->filter_configs)) { + if (flt_has_filter(px)) { px->be_req_ana |= AN_REQ_FLT_START_BE | AN_REQ_FLT_XFER_DATA | AN_REQ_FLT_END; px->be_rsp_ana |= AN_RES_FLT_START_BE | AN_RES_FLT_XFER_DATA | AN_RES_FLT_END; }