]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: server: switch the host_dn member to cebis_tree
authorWilly Tarreau <w@1wt.eu>
Mon, 7 Jul 2025 15:11:33 +0000 (17:11 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 16 Sep 2025 07:23:46 +0000 (09:23 +0200)
This member is used to index the hostname_dn contents for DNS resolution.
Let's replace it with a cebis_tree to save another 32 bytes (24 for the
node + 8 by avoiding the duplication of the pointer). The struct server is
now at 3904 bytes.

include/haproxy/resolvers-t.h
include/haproxy/server-t.h
src/resolvers.c
src/server_state.c

index 7c411b3db2e33919c3a94c4d43412f7488499981..fee7dd8d9ce5c3cd4d9ee8b2da1c088df8f12b5c 100644 (file)
@@ -297,7 +297,7 @@ struct resolv_srvrq {
        int                   hostname_dn_len;  /* string length of the server hostname in Domain Name format */
        struct resolv_requester *requester;     /* used to link to its DNS resolution */
        struct list attached_servers;           /* List of the servers free to use */
-       struct eb_root named_servers;           /* tree of servers indexed by hostnames found in server state file */
+       struct ceb_root *named_servers;         /* tree of servers indexed by hostnames found in server state file */
        struct list list;                       /* Next SRV RQ for the same proxy */
 };
 
index f55488d33b9c746ff620a5c58edad3ef80b14493..e4685b540e146d18296942c4ffe0ddcefc88441f 100644 (file)
@@ -454,7 +454,8 @@ struct server {
        char *lastaddr;                         /* the address string provided by the server-state file */
        struct resolv_options resolv_opts;
        int hostname_dn_len;                    /* string length of the server hostname in Domain Name format */
-       char *hostname_dn;                      /* server hostname in Domain Name format (name is lower cased) */
+       char *hostname_dn;                      /* server hostname in Domain Name format (name is lower cased), key to host_dn below */
+
        char *hostname;                         /* server hostname */
        struct sockaddr_storage init_addr;      /* plain IP address specified on the init-addr line */
        unsigned int init_addr_methods;         /* initial address setting, 3-bit per method, ends at 0, enough to store 10 entries */
@@ -505,7 +506,7 @@ struct server {
        struct resolv_srvrq *srvrq;             /* Pointer representing the DNS SRV requeest, if any */
        struct list srv_rec_item;               /* to attach server to a srv record item */
        struct list ip_rec_item;                /* to attach server to a A or AAAA record item */
-       struct ebpt_node host_dn;               /* hostdn store for srvrq and state file matching*/
+       struct ceb_node host_dn;                /* hostdn store for srvrq and state file matching (uses hostname_dn above) */
        struct list pp_tlvs;                    /* to send out PROXY protocol v2 TLVs */
        struct task *srvrq_check;               /* Task testing SRV record expiration date for this server */
        struct {
index c2da2315ca7044198cd3eb4b2fd9bc10b3627f38..9b6abc82a5b6f2270e65371b40d14d11ad392b80 100644 (file)
@@ -18,7 +18,7 @@
 
 #include <sys/types.h>
 
-#include <import/ebistree.h>
+#include <import/cebis_tree.h>
 
 #include <haproxy/action.h>
 #include <haproxy/api.h>
@@ -308,7 +308,7 @@ struct resolv_srvrq *new_resolv_srvrq(struct server *srv, char *fqdn)
                goto err;
        }
        LIST_INIT(&srvrq->attached_servers);
-       srvrq->named_servers = EB_ROOT;
+       srvrq->named_servers = NULL;
        LIST_APPEND(&resolv_srvrq_list, &srvrq->list);
        return srvrq;
 
@@ -744,8 +744,7 @@ static void resolv_srvrq_cleanup_srv(struct server *srv)
        HA_SPIN_LOCK(SERVER_LOCK, &srv->lock);
        srvrq_set_srv_down(srv);
 
-       ebpt_delete(&srv->host_dn);
-       srv->host_dn.key = NULL;
+       cebis_item_delete(&srv->srvrq->named_servers, host_dn, hostname_dn, srv);
 
        ha_free(&srv->hostname);
        ha_free(&srv->hostname_dn);
@@ -836,7 +835,6 @@ static void resolv_check_response(struct resolv_resolution *res)
 
                /* Now process SRV records */
                list_for_each_entry(req, &res->requesters, list) {
-                       struct ebpt_node *node;
                        char target[DNS_MAX_NAME_SIZE+1];
 
                        int i;
@@ -856,7 +854,7 @@ static void resolv_check_response(struct resolv_resolution *res)
                        /* If not empty we try to match a server
                         * in server state file tree with the same hostname
                         */
-                       if (!eb_is_empty(&srvrq->named_servers)) {
+                       if (!srvrq->named_servers) {
                                srv = NULL;
 
                                /* convert the key to lookup in lower case */
@@ -864,9 +862,8 @@ static void resolv_check_response(struct resolv_resolution *res)
                                        target[i] = tolower((unsigned char)item->data.target[i]);
                                target[i] = 0;
 
-                               node = ebis_lookup(&srvrq->named_servers, target);
-                               if (node) {
-                                       srv = ebpt_entry(node, struct server, host_dn);
+                               srv = cebis_item_lookup(&srvrq->named_servers, host_dn, hostname_dn, target, struct server);
+                               if (srv) {
                                        HA_SPIN_LOCK(SERVER_LOCK, &srv->lock);
 
                                        /* an entry was found with the same hostname
@@ -877,18 +874,16 @@ static void resolv_check_response(struct resolv_resolution *res)
                                        while (1) {
                                                if (srv->svc_port == item->port) {
                                                        /* server found, we remove it from tree */
-                                                       ebpt_delete(node);
-                                                       srv->host_dn.key = NULL;
+                                                       cebis_item_delete(&srvrq->named_servers, host_dn, hostname_dn, srv);
                                                        goto srv_found;
                                                }
 
                                                HA_SPIN_UNLOCK(SERVER_LOCK, &srv->lock);
 
-                                               node = ebpt_next(node);
-                                               if (!node)
+                                               srv = cebis_item_next(&srvrq->named_servers, host_dn, hostname_dn, srv);
+                                               if (!srv)
                                                        break;
 
-                                               srv = ebpt_entry(node, struct server, host_dn);
                                                HA_SPIN_LOCK(SERVER_LOCK, &srv->lock);
 
                                                if ((item->data_len != srv->hostname_dn_len)
index 098af82be902f44f4502a5239e07fc6f1c39cecf..0c9977fc42a1fde1f138cd59702b5a3a9a4be9ad 100644 (file)
@@ -13,7 +13,7 @@
 #include <errno.h>
 
 #include <import/eb64tree.h>
-#include <import/ebistree.h>
+#include <import/cebis_tree.h>
 
 #include <haproxy/api.h>
 #include <haproxy/backend.h>
@@ -415,10 +415,9 @@ static void srv_state_srv_update(struct server *srv, int version, char **params)
                 * since this server has an hostname
                 */
                LIST_DEL_INIT(&srv->srv_rec_item);
-               srv->host_dn.key = srv->hostname_dn;
 
                /* insert in tree and set the srvrq expiration date */
-               ebis_insert(&srv->srvrq->named_servers, &srv->host_dn);
+               cebis_item_insert(&srv->srvrq->named_servers, host_dn, hostname_dn, srv);
                task_schedule(srv->srvrq_check, tick_add(now_ms, srv->srvrq->resolvers->timeout.resolve +
                                                         srv->srvrq->resolvers->resolve_retries *
                                                         srv->srvrq->resolvers->timeout.retry));