]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEDIUM: server: do not forget to generate the dynamic servers ids
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Wed, 9 Jun 2021 07:58:47 +0000 (09:58 +0200)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Tue, 15 Jun 2021 09:42:53 +0000 (11:42 +0200)
If no id is specified by the user for a dynamic server, it is necessary
to generate a new one. This operation is now done at the end of 'add
server' CLI handler. The server is then inserted into the proxy ids
tree.

Without this, several features may be broken for dynamic servers. Among
them, there is the "first" lb algorithm, the persistence using
stick-tables or the uniqueness internal check of srv_parse_id.

This must be backported up to 2.4.

src/server.c

index 20121bf42fd2919d7df7d527bb5d193c0c3ffc17..ec4eab65d6eae2aca46d1e46613562ccdff71ab1 100644 (file)
@@ -4317,7 +4317,7 @@ static int cli_parse_add_server(char **args, char *payload, struct appctx *appct
        struct server *srv;
        char *be_name, *sv_name;
        int errcode, argc;
-       int i;
+       int next_id, i;
        const int parse_flags = SRV_PARSE_DYNAMIC|SRV_PARSE_PARSE_ADDR;
 
        usermsgs_clr("CLI");
@@ -4451,6 +4451,24 @@ static int cli_parse_add_server(char **args, char *payload, struct appctx *appct
                be->srv = srv;
        }
 
+       /* generate the server id if not manually specified */
+       if (!srv->puid) {
+               next_id = get_next_id(&be->conf.used_server_id, 1);
+               if (!next_id) {
+                       ha_alert("Cannot attach server : no id left in proxy\n");
+                       goto out;
+               }
+
+               srv->conf.id.key = srv->puid = next_id;
+               srv->conf.name.key = srv->id;
+       }
+
+       /* insert the server in the backend trees */
+       if (!(srv->flags & SRV_F_FORCED_ID)) {
+               eb32_insert(&be->conf.used_server_id, &srv->conf.id);
+               ebis_insert(&be->conf.used_server_name, &srv->conf.name);
+       }
+
        thread_release();
 
        ha_notice("New server registered.\n");