]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: server: accept server IDs above 2^31 and clarify error message
authorWilly Tarreau <w@1wt.eu>
Tue, 19 May 2026 14:59:37 +0000 (16:59 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 19 May 2026 17:11:25 +0000 (19:11 +0200)
Due to the check of the stored value instead of the parsed one, it was not
permitted to use server IDs above 2^31 while they are perfectly possible.
Let's refine the parsing and also update the error message to indicate the
range. The doc was also refined to reflect the relation with hash-key.

This may be backported though it wouldn't have any effect on working
configs.

doc/configuration.txt
src/server.c

index 0d6ba70d1b39cdc9451271334b989fbab8f323fb..65dafcb5d58d0ac17b09aab08eef26b41091b167 100644 (file)
@@ -18876,9 +18876,13 @@ healthcheck <name>
 id <value>
   May be used in the following contexts: tcp, http, log
 
-  Set a persistent ID for the server. This ID must be positive and unique for
-  the proxy. An unused ID will automatically be assigned if unset. The first
-  assigned value will be 1. This ID is currently only returned in statistics.
+  Set a persistent ID for the server. This ID must be a 32-bit positive number
+  and unique for the proxy. An unused ID will automatically be assigned if
+  unset. The first assigned value will be 1. This ID is currently only returned
+  in statistics, and is used to place LB nodes when using consistent hash
+  algorithms when "hash-key" is set to "id" (the default). In this case, only
+  the 28 lowest bits of the value are used (i.e. (id % 268435356)), so better
+  only use values comprised between 1 and this value to avoid overlap.
 
 idle-ping <delay>
   May be used in the following contexts: tcp, http, log
index 9d6a2f48175a073d3a4b9a3293a06bc60d1d84e4..819e1c05a9982f3fe0f24d5c13fdf27fffd165b2 100644 (file)
@@ -1313,19 +1313,20 @@ static int srv_parse_pool_max_conn(char **args, int *cur_arg, struct proxy *curp
 static int srv_parse_id(char **args, int *cur_arg, struct proxy *curproxy, struct server *newsrv, char **err)
 {
        struct server *target;
+       llong id;
 
        if (!*args[*cur_arg + 1]) {
                memprintf(err, "'%s' : expects an integer argument", args[*cur_arg]);
                return ERR_ALERT | ERR_FATAL;
        }
 
-       newsrv->puid = atol(args[*cur_arg + 1]);
-
-       if (newsrv->puid <= 0) {
-               memprintf(err, "'%s' : custom id has to be > 0", args[*cur_arg]);
+       id = atol(args[*cur_arg + 1]);
+       if (id < 1 || id > ~0U) {
+               memprintf(err, "'%s' : custom id has to be between 1 and 4294967295.", args[*cur_arg]);
                return ERR_ALERT | ERR_FATAL;
        }
 
+       newsrv->puid = id;
        target = server_find_by_id(curproxy, newsrv->puid);
        if (target) {
                memprintf(err, "'%s' : custom id %d already used at %s:%d ('server %s')",