From b4db3be86e03ec31055303d46056223bb989472e Mon Sep 17 00:00:00 2001 From: Amaury Denoyelle Date: Tue, 2 Jan 2024 14:39:26 +0100 Subject: [PATCH] BUG/MINOR: server: fix server_find_by_name() usage during parsing Since below commit, server_find_by_name() now search using 'used_server_id' proxy backend tree : 4bcfe30414005323a8d4ab986bce92bb736b59df OPTIM: server: eb lookup for server_find_by_name() This introduces a regression if server_find_by_name() is used via check_config_validity() during post-parsing. Indeed, used_server_id tree is populated at the same stage so it's possible to not found an existing server. This can cause incorrect rejection of previously valid configuration file. To fix this, servers are now inserted in used_server_id tree during parsing via parse_server(). This guarantees that server instances can be retrieved during post parsing. A known feature which uses server_find_by_name() during post parsing is attach-srv tcp-rule used for reverse HTTP. Prior to the current fix, a config was wrongly rejected if the rule was declared before the server line. This should not be backported unless the mentionned commit is. --- src/cfgparse.c | 2 -- src/server.c | 10 +++++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/cfgparse.c b/src/cfgparse.c index fc1ab8a30..feab258e0 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -3658,8 +3658,6 @@ out_uri_auth_compat: newsrv->conf.id.key = newsrv->puid = next_id; eb32_insert(&curproxy->conf.used_server_id, &newsrv->conf.id); } - newsrv->conf.name.key = newsrv->id; - ebis_insert(&curproxy->conf.used_server_name, &newsrv->conf.name); next_id++; newsrv = newsrv->next; diff --git a/src/server.c b/src/server.c index 147b1947d..b35d16caa 100644 --- a/src/server.c +++ b/src/server.c @@ -3008,6 +3008,9 @@ static int _srv_parse_tmpl_init(struct server *srv, struct proxy *px) /* Linked backwards first. This will be restablished after parsing. */ newsrv->next = px->srv; px->srv = newsrv; + + newsrv->conf.name.key = newsrv->id; + ebis_insert(&curproxy->conf.used_server_name, &newsrv->conf.name); } _srv_parse_set_id_from_prefix(srv, srv->tmpl_info.prefix, srv->tmpl_info.nb_low); @@ -3525,8 +3528,13 @@ int parse_server(const char *file, int linenum, char **args, goto out; } - if (parse_flags & SRV_PARSE_TEMPLATE) + if (parse_flags & SRV_PARSE_TEMPLATE) { _srv_parse_tmpl_init(newsrv, curproxy); + } + else if (!(parse_flags & SRV_PARSE_DEFAULT_SERVER)) { + newsrv->conf.name.key = newsrv->id; + ebis_insert(&curproxy->conf.used_server_name, &newsrv->conf.name); + } /* If the server id is fixed, insert it in the proxy used_id tree. * This is needed to detect a later duplicate id via srv_parse_id.