]> git.kaiwu.me - haproxy.git/commitdiff
MINOR: filters: Add flt_has_filter() and use it in proxy_finalize()
authorChristopher Faulet <cfaulet@haproxy.com>
Fri, 2 Oct 2026 16:05:46 +0000 (18:05 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 9 Oct 2026 14:17:36 +0000 (16:17 +0200)
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.

include/haproxy/filters.h
src/filters.c
src/proxy.c

index ea68a6bec0dc3ead29c402edef5ddb3e3a0b435c..680d51722f4d959c7d00843bfc136fc9b502563f 100644 (file)
@@ -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 <px> 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
index 482a2bae58d58efeb30765f5ecd0102906012dd1..7e344106fdf40a72c4806d6deefe65fe30d51fac 100644 (file)
@@ -406,6 +406,14 @@ list_filters(FILE *out)
        free(filters);
 }
 
+/* Returns 1 if the proxy <px> 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.
index a4e3af78e2a5f68483677fb88fc06272a19c4edd..c7a6688ad7a3ec07d6971baba4e98dd321c5aec1 100644 (file)
@@ -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;
                }