From: Christopher Faulet Date: Fri, 2 Oct 2026 09:44:06 +0000 (+0200) Subject: MINOR: filters: Use a proxy flag to detect use of legacy 'filter' directive X-Git-Tag: v3.5-dev9~77 X-Git-Url: https://git.kaiwu.me/?a=commitdiff_plain;h=b61dca1432a9e70e0ef22ec067e66bd52c406f34;p=haproxy.git MINOR: filters: Use a proxy flag to detect use of legacy 'filter' directive Replace the FLT_CFG_FL_LEGACY flag set on each filter configuration with the PR_FL_FILTER_LEGACY proxy flag, set when an explicit legacy "filter" directive is parsed. The legacy or instance mode is a property of the proxy, not of an individual filter configuration, so flt_check_config_mode() no longer needs to walk px->filter_configs to detect a legacy filter. Add the inline helper flt_use_legacy_filter() to expose the proxy flag and use it in flt_check_config_mode(). This prepares selecting the legacy filter configurations or the filter instances on a per-proxy basis. --- diff --git a/include/haproxy/filters-t.h b/include/haproxy/filters-t.h index 45fe183b2..2910f80f2 100644 --- a/include/haproxy/filters-t.h +++ b/include/haproxy/filters-t.h @@ -26,7 +26,6 @@ /* Flags set on a filter config */ #define FLT_CFG_FL_HTX 0x00000001 /* The filter can filter HTX streams */ -#define FLT_CFG_FL_LEGACY 0x00000002 /* Declared with the legacy "filter" directive */ /* Flags set on a filter instance */ #define FLT_FL_IS_BACKEND_FILTER 0x0001 /* The filter is a backend filter */ diff --git a/include/haproxy/filters.h b/include/haproxy/filters.h index b9253543b..4f87aeb53 100644 --- a/include/haproxy/filters.h +++ b/include/haproxy/filters.h @@ -184,6 +184,16 @@ struct flt_kw *flt_find_kw(const char *kw); void flt_dump_kws(char **out); void list_filters(FILE *out); +/* 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 + * filter instances (px->filter_instances and the flat per-side lists). + */ +static inline int flt_use_legacy_filter(const struct proxy *px) +{ + return px->flags & PR_FL_FILTER_LEGACY; +} + /* Helper function that returns the "global" state of filters attached to a * stream. */ static inline struct strm_flt * diff --git a/include/haproxy/proxy-t.h b/include/haproxy/proxy-t.h index f1de1a161..24b4c72a3 100644 --- a/include/haproxy/proxy-t.h +++ b/include/haproxy/proxy-t.h @@ -252,6 +252,7 @@ enum PR_SRV_STATE_FILE { #define PR_FL_BE_UNPUBLISHED 0x00000080 /* The proxy cannot be targeted by content switching rules */ #define PR_FL_DELETED 0x00000100 /* Proxy has been deleted and must be manipulated with care */ #define PR_FL_NON_PURGEABLE 0x00000200 /* Proxy referenced by config elements which prevent its runtime removal. */ +#define PR_FL_FILTER_LEGACY 0x00000400 /* An explicit legacy "filter" directive was used */ struct stream; diff --git a/src/filters.c b/src/filters.c index d9272bc87..c64d6788a 100644 --- a/src/filters.c +++ b/src/filters.c @@ -432,18 +432,12 @@ int flt_has_explicit_config(const struct proxy *px) */ static int flt_check_config_mode(struct proxy *px, int legacy, char **err) { - struct flt_conf *fconf; - if (legacy) { if (flt_has_explicit_config(px)) goto error; } - else { - list_for_each_entry(fconf, &px->filter_configs, list) { - if (fconf->flags & FLT_CFG_FL_LEGACY) - goto error; - } - } + else if (flt_use_legacy_filter(px)) + goto error; return 0; error: @@ -524,7 +518,7 @@ parse_filter(char **args, int section_type, struct proxy *curpx, goto error; } - fconf->flags |= FLT_CFG_FL_LEGACY; + curpx->flags |= PR_FL_FILTER_LEGACY; LIST_APPEND(&curpx->filter_configs, &fconf->list); } return 0; diff --git a/src/haload.c b/src/haload.c index 72c3fe191..0cb9c922c 100644 --- a/src/haload.c +++ b/src/haload.c @@ -2429,8 +2429,9 @@ static int hld_cfg_finalize(void) fconf->id = fcgi_flt_id; fconf->conf = fcgi_conf; fconf->ops = &fcgi_flt_ops; - fconf->flags |= FLT_CFG_FL_LEGACY; LIST_APPEND(&hld_proxy.filter_configs, &fconf->list); + + hld_proxy.flags |= PR_FL_FILTER_LEGACY; } ret = 1;