Skip to content

Commit 2c8ad11

Browse files
committed
MINOR: cfgparse: validate defaults proxies separately
Default proxies validation occurs during post-parsing. The objective is to report any tcp/http-rules which could not behave as expected. Previously, this was performed while looping over standard proxies list, when such proxy is referencing a default instance. This was enough as only named referenced proxies were kept after parsing. However, this is not the case anymore in the context of dynamic backends creation at runtime. As such, this patch now performs validation on every named defaults outside of the standard proxies list loop. This should not cause any behavior difference, as defaults are validated without using the proxy which relies on it. Along with this change, PR_FL_READY proxy flag is now removed. Its usage was only really needed for defaults, to avoid validating a same instance multiple times. With the validation of defaults in their own loop, it is now redundant.
1 parent 2a07dc9 commit 2c8ad11

2 files changed

Lines changed: 25 additions & 35 deletions

File tree

include/haproxy/proxy-t.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ enum PR_SRV_STATE_FILE {
242242
/* Proxy flags */
243243
#define PR_FL_DISABLED 0x01 /* The proxy was disabled in the configuration (not at runtime) */
244244
#define PR_FL_STOPPED 0x02 /* The proxy was stopped */
245-
#define PR_FL_READY 0x04 /* The proxy is ready to be used (initialized and configured) */
245+
/* 0x04 unused */
246246
#define PR_FL_EXPLICIT_REF 0x08 /* The default proxy is explicitly referenced by another proxy */
247247
#define PR_FL_IMPLICIT_REF 0x10 /* The default proxy is implicitly referenced by another proxy */
248248
#define PR_FL_PAUSED 0x20 /* The proxy was paused at run time (reversible) */

src/cfgparse.c

Lines changed: 24 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2270,7 +2270,7 @@ int parse_cfg(const struct cfgfile *cfg)
22702270
int check_config_validity()
22712271
{
22722272
int cfgerr = 0;
2273-
struct proxy *init_proxies_list = NULL;
2273+
struct proxy *init_proxies_list = NULL, *defpx;
22742274
struct stktable *t;
22752275
struct server *newsrv = NULL;
22762276
struct mt_list back;
@@ -2358,6 +2358,29 @@ int check_config_validity()
23582358
goto out;
23592359
}
23602360

2361+
list_for_each_entry(defpx, &defaults_list, el) {
2362+
/* check validity for 'tcp-request' layer 4/5/6/7 rules */
2363+
cfgerr += check_action_rules(&defpx->tcp_req.l4_rules, defpx, &err_code);
2364+
cfgerr += check_action_rules(&defpx->tcp_req.l5_rules, defpx, &err_code);
2365+
cfgerr += check_action_rules(&defpx->tcp_req.inspect_rules, defpx, &err_code);
2366+
cfgerr += check_action_rules(&defpx->tcp_rep.inspect_rules, defpx, &err_code);
2367+
cfgerr += check_action_rules(&defpx->http_req_rules, defpx, &err_code);
2368+
cfgerr += check_action_rules(&defpx->http_res_rules, defpx, &err_code);
2369+
cfgerr += check_action_rules(&defpx->http_after_res_rules, defpx, &err_code);
2370+
2371+
err = NULL;
2372+
i = smp_resolve_args(defpx, &err);
2373+
cfgerr += i;
2374+
if (i) {
2375+
indent_msg(&err, 8);
2376+
ha_alert("%s%s\n", i > 1 ? "multiple argument resolution errors:" : "", err);
2377+
ha_free(&err);
2378+
}
2379+
else {
2380+
cfgerr += acl_find_targets(defpx);
2381+
}
2382+
}
2383+
23612384
/* starting to initialize the main proxies list */
23622385
init_proxies_list = proxies_list;
23632386

@@ -2403,37 +2426,6 @@ int check_config_validity()
24032426
continue;
24042427
}
24052428

2406-
/* The current proxy is referencing a default proxy. We must
2407-
* finalize its config, but only once. If the default proxy is
2408-
* ready (PR_FL_READY) it means it was already fully configured.
2409-
*/
2410-
if (curproxy->defpx) {
2411-
if (!(curproxy->defpx->flags & PR_FL_READY)) {
2412-
/* check validity for 'tcp-request' layer 4/5/6/7 rules */
2413-
cfgerr += check_action_rules(&curproxy->defpx->tcp_req.l4_rules, curproxy->defpx, &err_code);
2414-
cfgerr += check_action_rules(&curproxy->defpx->tcp_req.l5_rules, curproxy->defpx, &err_code);
2415-
cfgerr += check_action_rules(&curproxy->defpx->tcp_req.inspect_rules, curproxy->defpx, &err_code);
2416-
cfgerr += check_action_rules(&curproxy->defpx->tcp_rep.inspect_rules, curproxy->defpx, &err_code);
2417-
cfgerr += check_action_rules(&curproxy->defpx->http_req_rules, curproxy->defpx, &err_code);
2418-
cfgerr += check_action_rules(&curproxy->defpx->http_res_rules, curproxy->defpx, &err_code);
2419-
cfgerr += check_action_rules(&curproxy->defpx->http_after_res_rules, curproxy->defpx, &err_code);
2420-
2421-
err = NULL;
2422-
i = smp_resolve_args(curproxy->defpx, &err);
2423-
cfgerr += i;
2424-
if (i) {
2425-
indent_msg(&err, 8);
2426-
ha_alert("%s%s\n", i > 1 ? "multiple argument resolution errors:" : "", err);
2427-
ha_free(&err);
2428-
}
2429-
else
2430-
cfgerr += acl_find_targets(curproxy->defpx);
2431-
2432-
/* default proxy is now ready. Set the right FE/BE capabilities */
2433-
curproxy->defpx->flags |= PR_FL_READY;
2434-
}
2435-
}
2436-
24372429
/* check and reduce the bind-proc of each listener */
24382430
list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) {
24392431
int mode = conn_pr_mode_to_proto_mode(curproxy->mode);
@@ -3860,7 +3852,6 @@ int check_config_validity()
38603852
if (curproxy->task) {
38613853
curproxy->task->context = curproxy;
38623854
curproxy->task->process = manage_proxy;
3863-
curproxy->flags |= PR_FL_READY;
38643855
}
38653856
else {
38663857
ha_alert("Proxy '%s': no more memory when trying to allocate the management task\n",
@@ -3937,7 +3928,6 @@ int check_config_validity()
39373928
* Note that ->srv is used by the local peer of a new process to connect to the local peer
39383929
* of an old process.
39393930
*/
3940-
curpeers->peers_fe->flags |= PR_FL_READY;
39413931
p = curpeers->remote;
39423932
while (p) {
39433933
struct peer *other_peer;

0 commit comments

Comments
 (0)