From: Christopher Faulet Date: Wed, 28 Oct 2026 08:01:51 +0000 (+0100) Subject: MINOR: filters: Pre-initialize the instances in check_config_validity() X-Git-Tag: v3.5-dev10~24 X-Git-Url: https://git.kaiwu.me/?a=commitdiff_plain;h=49726f3087760282228187eceee92b4381739551;p=haproxy.git MINOR: filters: Pre-initialize the instances in check_config_validity() 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(). --- diff --git a/include/haproxy/filters.h b/include/haproxy/filters.h index b9e27e434..cb7e07851 100644 --- a/include/haproxy/filters.h +++ b/include/haproxy/filters.h @@ -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); diff --git a/src/cfgparse.c b/src/cfgparse.c index 2097f24af..3459d55c2 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -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 diff --git a/src/filters.c b/src/filters.c index e4994ff0f..46fa7e72a 100644 --- a/src/filters.c +++ b/src/filters.c @@ -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);