]> git.kaiwu.me - haproxy.git/commitdiff
MINOR: filters: Pre-initialize the instances in check_config_validity()
authorChristopher Faulet <cfaulet@haproxy.com>
Wed, 28 Oct 2026 08:01:51 +0000 (09:01 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Wed, 28 Oct 2026 08:12:11 +0000 (09:12 +0100)
The filter instances were pre-checked by a callback registered at the
pre-check stage, flt_precheck_instances_all(). This was annoying for
the modules adding instances after the configuration parsing, from
their own pre-check callback: the pre-check callbacks run before
check_config_validity(), so the instances they add are never
finalized.

The pre-check of all instances now runs from check_config_validity(),
before the servers are initialized: the default filter mode is
applied, then every instance is finalized by the parse callback of its
class, and the filter-enable/filter-disable and filter-sequence
directives are applied, as before. The pre-check callbacks may add
instances when the whole configuration was parsed, they are then
pre-initialized like the ones declared by the configuration.

The functions are renamed accordingly: flt_precheck_instances_all()
becomes flt_preinit_instances_all(), now exported, and
flt_precheck_instances(), flt_precheck_class_instances() and
flt_precheck_instance() respectively become flt_preinit_instances(),
flt_preinit_class_instances() and flt_preinit_instance().

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

index b9e27e434b861008f64355e23bde203dfb01f364..cb7e07851f2b48574236180c52d4a9cf34c25873 100644 (file)
@@ -150,6 +150,8 @@ int fcgi_flt_parse_instance(char **args, struct proxy *px, struct filter_instanc
 
 void flt_deinit(struct proxy *p);
 int  flt_check(struct proxy *p);
+
+int  flt_preinit_instances_all(void);
 int  flt_has_explicit_config(const struct proxy *px);
 int  flt_copy_instances(struct proxy *px, const struct proxy *defpx);
 void flt_free_instances(struct proxy *px);
index 2097f24aff11b48e781bb97b5f0f5fbfd38e28f5..3459d55c27aa983a3be02433af1c5950ac23df7a 100644 (file)
@@ -2379,6 +2379,10 @@ int check_config_validity()
        if (err_code != ERR_NONE)
                goto out;
 
+       /* Pre-initialize the filter instances of all proxies */
+       err_code |= flt_preinit_instances_all();
+       if (err_code & ERR_CODE)
+               goto out;
        /*
         * we must finish to initialize certain things on the servers,
         * as some of the fields may be accessed soon
index e4994ff0f7ba1fbf94c94dd57c1a203c9ed377dd..46fa7e72a064e6cf9cbad9146bb4740b3796bba1 100644 (file)
@@ -3119,7 +3119,7 @@ static void flt_flatten_instances(struct proxy *px)
  * post-parsing stage. Returns a combination of ERR_* flags, ERR_NONE on
  * success.
  */
-static int flt_precheck_instance(struct proxy *proxy, struct filter_instance *inst)
+static int flt_preinit_instance(struct proxy *proxy, struct filter_instance *inst)
 {
        char *err = NULL;
 
@@ -3160,7 +3160,7 @@ static int flt_precheck_instance(struct proxy *proxy, struct filter_instance *in
  * instance is allowed for classes without FLT_CLS_FL_MULTI. Returns a
  * combination of ERR_* flags, ERR_NONE on success.
  */
-static int flt_precheck_class_instances(struct proxy *proxy, struct filter_class_ref *ref)
+static int flt_preinit_class_instances(struct proxy *proxy, struct filter_class_ref *ref)
 {
        struct filter_instance *inst;
        int err_code = ERR_NONE;
@@ -3179,11 +3179,11 @@ static int flt_precheck_class_instances(struct proxy *proxy, struct filter_class
        }
 
        list_for_each_entry(inst, &ref->instances, global.list)
-               err_code |= flt_precheck_instance(proxy, inst);
+               err_code |= flt_preinit_instance(proxy, inst);
        return err_code;
 }
 
-static int flt_precheck_instances(struct proxy *proxy)
+static int flt_preinit_instances(struct proxy *proxy)
 {
        struct filter_class_ref *ref;
        int err_code = ERR_NONE;
@@ -3196,7 +3196,7 @@ static int flt_precheck_instances(struct proxy *proxy)
 
        /* Finalize every instance once, following the global class order. */
        list_for_each_entry(ref, &proxy->conf.filter_refs, list)
-               err_code |= flt_precheck_class_instances(proxy, ref);
+               err_code |= flt_preinit_class_instances(proxy, ref);
        return err_code;
 }
 
@@ -3315,8 +3315,8 @@ static void flt_apply_default_mode(struct proxy *px)
        }
 }
 
-/* Calls flt_precheck_instances() for all proxies, see above */
-static int flt_precheck_instances_all()
+/* Calls flt_preinit_instances() for all proxies, see above */
+int flt_preinit_instances_all(void)
 {
        struct proxy *px;
        int err_code = ERR_NONE;
@@ -3332,7 +3332,7 @@ static int flt_precheck_instances_all()
                if (px->flags & (PR_FL_DISABLED|PR_FL_STOPPED))
                        continue;
 
-               err_code |= flt_precheck_instances(px);
+               err_code |= flt_preinit_instances(px);
                if (err_code & (ERR_ABORT|ERR_FATAL)) {
                        ha_alert("Failed to parse the filter instances of proxy '%s'.\n",
                                 px->id);
@@ -3411,8 +3411,9 @@ static void flt_twork_done(union twork_arg arg, union twork_arg ret)
  * from its defaults section were copied): the parse callback of every
  * instance is called to produce its filter configuration, the
  * filter-enable/filter-disable and filter-sequence directives are applied,
- * and the three evaluation orders are flattened. This mirrors the pre-check
- * stage of the startup, so flt_start_new_proxy() must be called before
+ * and the three evaluation orders are flattened. This mirrors the
+ * pre-initialization of the instances at startup, so
+ * flt_start_new_proxy() must be called before
  * proxy_finalize(), while the threads are isolated, so that the filter
  * analyzers are enabled if the proxy has filters.
  * Returns a combination of ERR_* flags, ERR_NONE on success.
@@ -3426,7 +3427,7 @@ int flt_start_new_proxy(struct proxy *px)
         */
        flt_apply_default_mode(px);
 
-       err_code |= flt_precheck_instances(px);
+       err_code |= flt_preinit_instances(px);
        if (!(err_code & (ERR_ABORT|ERR_FATAL)))
                err_code |= flt_enable_filters(px);
        if (!(err_code & (ERR_ABORT|ERR_FATAL)))
@@ -4175,7 +4176,6 @@ static void filter_init_classes(void)
 
 
 
-REGISTER_PRE_CHECK(flt_precheck_instances_all);
 REGISTER_PRE_CHECK(flt_precheck_classes);
 REGISTER_POST_PROXY_CHECK(flt_check_instances);
 REGISTER_POST_CHECK(flt_init_all);