]> git.kaiwu.me - haproxy.git/commitdiff
MINOR: filters: Add a function to find a legacy filter configuration during parsing
authorChristopher Faulet <cfaulet@haproxy.com>
Tue, 27 Oct 2026 13:07:10 +0000 (14:07 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Tue, 27 Oct 2026 13:08:45 +0000 (14:08 +0100)
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.

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

index 9f4ffa1188f19f20f5fa6ae62a5868aa2b54f5ee..b9e27e434b861008f64355e23bde203dfb01f364 100644 (file)
@@ -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);
index c9e453719dd32b2c490679768d11b1b0e4bc544a..e4994ff0f7ba1fbf94c94dd57c1a203c9ed377dd 100644 (file)
@@ -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 <px> with the id
+ * <flt_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 <match> is not NULL, it is called with each
+ * candidate and <data> 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 <inst> in the global class references of <px> and on each side its
  * class is placed on. All links were initialized on allocation.