]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: server: add server_index_id() to index a server by its ID
authorWilly Tarreau <w@1wt.eu>
Sat, 23 Aug 2025 17:33:52 +0000 (19:33 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 16 Sep 2025 07:23:46 +0000 (09:23 +0200)
This avoids needlessly exposing the tree's root and the mechanics outside
of the low-level code.

include/haproxy/server.h
src/cfgparse.c
src/server.c

index ad9036109c6d392481485e75e00735225ca566b1..606c1f4e8fb3a37b9b0a9fa12907569a27e2861b 100644 (file)
@@ -196,6 +196,12 @@ static inline void srv_free(struct server **srv_ptr)
        *srv_ptr = NULL;
 }
 
+/* index server <srv>'s id into proxy <px>'s used_server_id */
+static inline void server_index_id(struct proxy *px, struct server *srv)
+{
+       eb32_insert(&px->conf.used_server_id, &srv->conf.id);
+}
+
 /* increase the number of cumulated streams on the designated server */
 static inline void srv_inc_sess_ctr(struct server *s)
 {
index b9806bd4607ffe51895fefeaaf1014d46f4ab0a9..b03628a067bf2fce46e5400dcb619c891b8202f2 100644 (file)
@@ -3728,7 +3728,7 @@ out_uri_auth_compat:
                                 */
                                next_id = server_get_next_id(curproxy, next_id);
                                newsrv->conf.id.key = newsrv->puid = next_id;
-                               eb32_insert(&curproxy->conf.used_server_id, &newsrv->conf.id);
+                               server_index_id(curproxy, newsrv);
                        }
 
                        next_id++;
index a473b56a54c91909effdd2922bf749acf5ac9b4e..94b76917a557cdff759afcb770cbad339476b78c 100644 (file)
@@ -4017,7 +4017,7 @@ int parse_server(const char *file, int linenum, char **args,
         * check_config_validity.
         */
        if (newsrv->flags & SRV_F_FORCED_ID)
-               eb32_insert(&curproxy->conf.used_server_id, &newsrv->conf.id);
+               server_index_id(curproxy, newsrv);
 
        HA_DIAG_WARNING_COND((curproxy->cap & PR_CAP_LB) && !newsrv->uweight,
                             "configured with weight of 0 will never be selected by load balancing algorithms\n");
@@ -6254,7 +6254,7 @@ static int cli_parse_add_server(char **args, char *payload, struct appctx *appct
        }
 
        /* insert the server in the backend trees */
-       eb32_insert(&be->conf.used_server_id, &srv->conf.id);
+       server_index_id(be, srv);
        cebis_item_insert(&be->conf.used_server_name, conf.name_node, id, srv);
        /* addr_key could be NULL if FQDN resolution is postponed (ie: add server from cli) */
        if (srv->addr_key)