]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: proxy: Store server_id_hdr_name as a `struct ist`
authorTim Duesterhus <tim@bastelstu.be>
Fri, 4 Mar 2022 23:52:43 +0000 (00:52 +0100)
committerWilly Tarreau <w@1wt.eu>
Wed, 9 Mar 2022 06:51:27 +0000 (07:51 +0100)
The server_id_hdr_name is already processed as an ist in various locations lets
also just store it as such.

see 0643b0e7e ("MINOR: proxy: Make `header_unique_id` a `struct ist`") for a
very similar past commit.

include/haproxy/proxy-t.h
src/cfgparse-listen.c
src/mux_fcgi.c
src/mux_h1.c
src/mux_h2.c
src/proxy.c

index 805e1b4529e968f3267ec3c56f093dbed11308cc..80431757ed949706e097120e9e542ca13ec78a64 100644 (file)
@@ -354,8 +354,7 @@ struct proxy {
        struct net_addr except_xot_net;         /* don't x-original-to for this address. */
        struct ist fwdfor_hdr_name;                     /* header to use - default: "x-forwarded-for" */
        struct ist orgto_hdr_name;                      /* header to use - default: "x-original-to" */
-       char *server_id_hdr_name;                   /* the header to use to send the server id (name) */
-       int server_id_hdr_len;                      /* the length of the id (name) header... name */
+       struct ist server_id_hdr_name;                   /* the header to use to send the server id (name) */
        int conn_retries;                       /* maximum number of connect retries */
        unsigned int retry_type;                /* Type of retry allowed */
        int redispatch_after;                   /* number of retries before redispatch */
index 121f1deac97cc441a4a0acbbea0e63e535ee1f66..216e6d8d577fc7c9f2917465964bf781da7948e7 100644 (file)
@@ -1383,12 +1383,11 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
                }
 
                /* set the desired header name, in lower case */
-               free(curproxy->server_id_hdr_name);
-               curproxy->server_id_hdr_name = strdup(args[1]);
-               if (!curproxy->server_id_hdr_name)
+               istfree(&curproxy->server_id_hdr_name);
+               curproxy->server_id_hdr_name = istdup(ist(args[1]));
+               if (!isttest(curproxy->server_id_hdr_name))
                        goto alloc_error;
-               curproxy->server_id_hdr_len  = strlen(curproxy->server_id_hdr_name);
-               ist2bin_lc(curproxy->server_id_hdr_name, ist2(curproxy->server_id_hdr_name, curproxy->server_id_hdr_len));
+               ist2bin_lc(istptr(curproxy->server_id_hdr_name), curproxy->server_id_hdr_name);
        }
        else if (strcmp(args[0], "block") == 0) {
                ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. Use 'http-request deny' which uses the exact same syntax.\n", file, linenum, args[0]);
index b5b28074926721b3dfe66bec34add3e044548e8f..a22bc9391f4ddfb3feb1fc15069a5a91d6ed3876 100644 (file)
@@ -2043,8 +2043,7 @@ static size_t fcgi_strm_send_params(struct fcgi_conn *fconn, struct fcgi_strm *f
                                        }
 
                                        /* Skip header if same name is used to add the server name */
-                                       if (fconn->proxy->server_id_hdr_name &&
-                                           isteq(p.n, ist2(fconn->proxy->server_id_hdr_name, fconn->proxy->server_id_hdr_len)))
+                                       if (isttest(fconn->proxy->server_id_hdr_name) && isteq(p.n, fconn->proxy->server_id_hdr_name))
                                                break;
 
                                        memcpy(trash.area, "http_", 5);
@@ -2062,15 +2061,15 @@ static size_t fcgi_strm_send_params(struct fcgi_conn *fconn, struct fcgi_strm *f
                                break;
 
                        case HTX_BLK_EOH:
-                               if (fconn->proxy->server_id_hdr_name) {
+                               if (isttest(fconn->proxy->server_id_hdr_name)) {
                                        struct server *srv = objt_server(fconn->conn->target);
 
                                        if (!srv)
                                                goto done;
 
-                                       memcpy(trash.area, "http_", 5);
-                                       memcpy(trash.area+5, fconn->proxy->server_id_hdr_name, fconn->proxy->server_id_hdr_len);
-                                       p.n = ist2(trash.area, fconn->proxy->server_id_hdr_len+5);
+                                       p.n = ist2(trash.area, 0);
+                                       istcat(&p.n, ist("http_"), trash.size);
+                                       istcat(&p.n, fconn->proxy->server_id_hdr_name, trash.size);
                                        p.v = ist(srv->id);
 
                                        if (!fcgi_encode_param(&outbuf, &p)) {
index 7de0862559812196b6a29df49db5f92a7d06a1a1..3ddf6ef8654b27fe17ccb7f9caa327912f3a8c89 100644 (file)
@@ -2143,8 +2143,8 @@ static size_t h1_process_mux(struct h1c *h1c, struct buffer *buf, size_t count)
                                }
 
                                /* Skip header if same name is used to add the server name */
-                               if (!(h1m->flags & H1_MF_RESP) && h1c->px->server_id_hdr_name &&
-                                   isteqi(n, ist2(h1c->px->server_id_hdr_name, h1c->px->server_id_hdr_len)))
+                               if (!(h1m->flags & H1_MF_RESP) && isttest(h1c->px->server_id_hdr_name) &&
+                                   isteqi(n, h1c->px->server_id_hdr_name))
                                        goto skip_hdr;
 
                                /* Try to adjust the case of the header name */
@@ -2213,11 +2213,11 @@ static size_t h1_process_mux(struct h1c *h1c, struct buffer *buf, size_t count)
 
                                /* Now add the server name to a header (if requested) */
                                if (!(h1s->flags & H1S_F_HAVE_SRV_NAME) &&
-                                   !(h1m->flags & H1_MF_RESP) && h1c->px->server_id_hdr_name) {
+                                   !(h1m->flags & H1_MF_RESP) && isttest(h1c->px->server_id_hdr_name)) {
                                        struct server *srv = objt_server(h1c->conn->target);
 
                                        if (srv) {
-                                               n = ist2(h1c->px->server_id_hdr_name, h1c->px->server_id_hdr_len);
+                                               n = h1c->px->server_id_hdr_name;
                                                v = ist(srv->id);
 
                                                /* Try to adjust the case of the header name */
index 4fed9b2dfc1709703d19bcd4dc4823b9e17c8cc2..0c312ba19cc736e283024851c8cef137bf3d98ec 100644 (file)
@@ -5349,8 +5349,8 @@ static size_t h2s_bck_make_req_headers(struct h2s *h2s, struct htx *htx)
                        list[hdr].v = htx_get_blk_value(htx, blk);
 
                        /* Skip header if same name is used to add the server name */
-                       if ((h2c->flags & H2_CF_IS_BACK) && h2c->proxy->server_id_hdr_name &&
-                           isteq(list[hdr].n, ist2(h2c->proxy->server_id_hdr_name, h2c->proxy->server_id_hdr_len)))
+                       if ((h2c->flags & H2_CF_IS_BACK) && isttest(h2c->proxy->server_id_hdr_name) &&
+                           isteq(list[hdr].n, h2c->proxy->server_id_hdr_name))
                                continue;
 
                        /* Convert connection: upgrade to Extended connect from rfc 8441 */
@@ -5416,11 +5416,11 @@ static size_t h2s_bck_make_req_headers(struct h2s *h2s, struct htx *htx)
        BUG_ON(!sl);
 
        /* Now add the server name to a header (if requested) */
-       if ((h2c->flags & H2_CF_IS_BACK) && h2c->proxy->server_id_hdr_name) {
+       if ((h2c->flags & H2_CF_IS_BACK) && isttest(h2c->proxy->server_id_hdr_name)) {
                struct server *srv = objt_server(h2c->conn->target);
 
                if (srv) {
-                       list[hdr].n = ist2(h2c->proxy->server_id_hdr_name, h2c->proxy->server_id_hdr_len);
+                       list[hdr].n = h2c->proxy->server_id_hdr_name;
                        list[hdr].v = ist(srv->id);
                        hdr++;
                }
index 33328e2ccc34eabcc292dd189f3c260860d9b7a7..e45df8c77531bb9384289224330d746dce1a603a 100644 (file)
@@ -1441,7 +1441,7 @@ void proxy_free_defaults(struct proxy *defproxy)
        ha_free(&defproxy->conn_src.iface_name);
        istfree(&defproxy->fwdfor_hdr_name);
        istfree(&defproxy->orgto_hdr_name);
-       ha_free(&defproxy->server_id_hdr_name); defproxy->server_id_hdr_len = 0;
+       istfree(&defproxy->server_id_hdr_name);
 
        list_for_each_entry_safe(acl, aclb, &defproxy->acl, list) {
                LIST_DELETE(&acl->list);
@@ -1607,10 +1607,8 @@ static int proxy_defproxy_cpy(struct proxy *curproxy, const struct proxy *defpro
        if (isttest(defproxy->orgto_hdr_name))
                curproxy->orgto_hdr_name = istdup(defproxy->orgto_hdr_name);
 
-       if (defproxy->server_id_hdr_len) {
-               curproxy->server_id_hdr_len  = defproxy->server_id_hdr_len;
-               curproxy->server_id_hdr_name = strdup(defproxy->server_id_hdr_name);
-       }
+       if (isttest(defproxy->server_id_hdr_name))
+               curproxy->server_id_hdr_name = istdup(defproxy->server_id_hdr_name);
 
        /* initialize error relocations */
        if (!proxy_dup_default_conf_errors(curproxy, defproxy, &tmpmsg)) {