]> git.kaiwu.me - haproxy.git/commitdiff
MINOR: filters: Use a proxy flag to detect use of legacy 'filter' directive
authorChristopher Faulet <cfaulet@haproxy.com>
Fri, 2 Oct 2026 09:44:06 +0000 (11:44 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 9 Oct 2026 14:17:36 +0000 (16:17 +0200)
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.

include/haproxy/filters-t.h
include/haproxy/filters.h
include/haproxy/proxy-t.h
src/filters.c
src/haload.c

index 45fe183b2d9164870432698cfccbe24dcacdb0cb..2910f80f20145b4ba9066bb03218ba71784f8623 100644 (file)
@@ -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 */
index b9253543b2c655d52a37f46f0eb22b20518ddd39..4f87aeb53c3f6af9fda6d3806e71de36db1caf4e 100644 (file)
@@ -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 <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
+ * 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 *
index f1de1a161b717e8a6f3946a32b021411a5a807f0..24b4c72a3739b6ea8f32041aaa833e666689178a 100644 (file)
@@ -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;
 
index d9272bc870a3453263144ed1999b0d54bac2b167..c64d6788aebaf7ade112ad0dd48568ec4e475b1b 100644 (file)
@@ -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;
index 72c3fe19177e06780bf6f4374161b3039dfe0ef9..0cb9c922c9fa2b54e6509a1d2f559474a2a13b9c 100644 (file)
@@ -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;