]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: server: fix server_find_by_name() usage during parsing
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Tue, 2 Jan 2024 13:39:26 +0000 (14:39 +0100)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Tue, 2 Jan 2024 14:52:47 +0000 (15:52 +0100)
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
src/server.c

index fc1ab8a306cd82f2e22cc9916a93917b35f4523c..feab258e08ab5f9d789f66d64c69f604f7b6a4d2 100644 (file)
@@ -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;
index 147b1947d7231597cff0a7803e8e7687127af253..b35d16caa573bdba53bc13972988bd5b64aa500e 100644 (file)
@@ -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.