]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: backend: make headers and RDP cookie also use arg_str/len
authorWilly Tarreau <w@1wt.eu>
Mon, 14 Jan 2019 14:28:53 +0000 (15:28 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 14 Jan 2019 18:33:17 +0000 (19:33 +0100)
These ones used to rely on separate variables called hh_name/hh_len
but they are exclusive with the former. Let's use the same variable
which becomes a generic argument name and length for the LB algorithm.

include/types/backend.h
include/types/proxy.h
src/backend.c
src/cfgparse-listen.c

index ec1f5a9bcafd4399296b4c7f928a4fc54dbc631c..3271eea4c7dd0407d3be4eef0cdbc846549ce954 100644 (file)
@@ -144,7 +144,7 @@ struct lbprm {
        int tot_used;                   /* total number of servers used for LB */
        int wmult;                      /* ratio between user weight and effective weight */
        int wdiv;                       /* ratio between effective weight and user weight */
-       char *arg_str;                  /* name of the URL parameter used for hashing */
+       char *arg_str;                  /* name of the URL parameter/header/cookie used for hashing */
        int   arg_len;                  /* strlen(arg_str), computed only once */
        struct server *fbck;            /* first backup server when !PR_O_USE_ALL_BK, or NULL */
        struct lb_map map;              /* LB parameters for map-based algorithms */
index 39e9940394b61304f580e73e9178c48c400bd7cd..448b5a2445adfd635656d253bc9f411a8c0389db 100644 (file)
@@ -323,8 +323,6 @@ struct proxy {
        int  uri_len_limit;                     /* character limit for uri balancing algorithm */
        int  uri_dirs_depth1;                   /* directories+1 (slashes) limit for uri balancing algorithm */
        int  uri_whole;                         /* if != 0, calculates the hash from the whole uri. Still honors the len_limit and dirs_depth1 */
-       char *hh_name;                          /* name of the header parameter used for hashing */
-       int  hh_len;                            /* strlen(hh_name), computed only once */
        int  hh_match_domain;                   /* toggle use of special match function */
        char *capture_name;                     /* beginning of the name of the cookie to capture */
        int  capture_namelen;                   /* length of the cookie name to match */
index 9b6f316f87ddae4cd33a6f6ba9b98ef2a00a284d..7a1acec76c76b3d63c362dac4a07f95958320b37 100644 (file)
@@ -401,7 +401,7 @@ static struct server *get_server_hh(struct stream *s, const struct server *avoid
        unsigned int hash = 0;
        struct http_txn *txn  = s->txn;
        struct proxy    *px   = s->be;
-       unsigned int     plen = px->hh_len;
+       unsigned int     plen = px->lbprm.arg_len;
        unsigned long    len;
        struct hdr_ctx   ctx;
        const char      *p;
@@ -414,7 +414,7 @@ static struct server *get_server_hh(struct stream *s, const struct server *avoid
        ctx.idx = 0;
 
        /* if the message is chunked, we skip the chunk size, but use the value as len */
-       http_find_header2(px->hh_name, plen, c_ptr(&s->req, -http_hdr_rewind(&txn->req)), &txn->hdr_idx, &ctx);
+       http_find_header2(px->lbprm.arg_str, plen, c_ptr(&s->req, -http_hdr_rewind(&txn->req)), &txn->hdr_idx, &ctx);
 
        /* if the header is not found or empty, let's fallback to round robin */
        if (!ctx.idx || !ctx.vlen)
@@ -424,7 +424,7 @@ static struct server *get_server_hh(struct stream *s, const struct server *avoid
        if (px->lbprm.tot_used == 1)
                goto hash_done;
 
-       /* Found a the hh_name in the headers.
+       /* Found the param_name in the headers.
         * we will compute the hash based on this value ctx.val.
         */
        len = ctx.vlen;
@@ -490,7 +490,7 @@ static struct server *get_server_rch(struct stream *s, const struct server *avoi
        rewind = co_data(&s->req);
        c_rew(&s->req, rewind);
 
-       ret = fetch_rdp_cookie_name(s, &smp, px->hh_name, px->hh_len);
+       ret = fetch_rdp_cookie_name(s, &smp, px->lbprm.arg_str, px->lbprm.arg_len);
        len = smp.data.u.str.data;
 
        c_adv(&s->req, rewind);
@@ -502,7 +502,7 @@ static struct server *get_server_rch(struct stream *s, const struct server *avoi
        if (px->lbprm.tot_used == 1)
                goto hash_done;
 
-       /* Found a the hh_name in the headers.
+       /* Found the param_name in the headers.
         * we will compute the hash based on this value ctx.val.
         */
        hash = gen_hash(px, smp.data.u.str.area, len);
@@ -1799,9 +1799,9 @@ int backend_parse_balance(const char **args, char **err, struct proxy *curproxy)
                curproxy->lbprm.algo &= ~BE_LB_ALGO;
                curproxy->lbprm.algo |= BE_LB_ALGO_HH;
 
-               free(curproxy->hh_name);
-               curproxy->hh_len  = end - beg;
-               curproxy->hh_name = my_strndup(beg, end - beg);
+               free(curproxy->lbprm.arg_str);
+               curproxy->lbprm.arg_len = end - beg;
+               curproxy->lbprm.arg_str = my_strndup(beg, end - beg);
                curproxy->hh_match_domain = 0;
 
                if (*args[1]) {
@@ -1827,14 +1827,14 @@ int backend_parse_balance(const char **args, char **err, struct proxy *curproxy)
                                return -1;
                        }
 
-                       free(curproxy->hh_name);
-                       curproxy->hh_name = my_strndup(beg, end - beg);
-                       curproxy->hh_len  = end - beg;
+                       free(curproxy->lbprm.arg_str);
+                       curproxy->lbprm.arg_str = my_strndup(beg, end - beg);
+                       curproxy->lbprm.arg_len = end - beg;
                }
                else if ( *(args[0] + 10 ) == '\0' ) { /* default cookie name 'mstshash' */
-                       free(curproxy->hh_name);
-                       curproxy->hh_name = strdup("mstshash");
-                       curproxy->hh_len  = strlen(curproxy->hh_name);
+                       free(curproxy->lbprm.arg_str);
+                       curproxy->lbprm.arg_str = strdup("mstshash");
+                       curproxy->lbprm.arg_len = strlen(curproxy->lbprm.arg_str);
                }
                else { /* syntax */
                        memprintf(err, "rdp-cookie : missing cookie name.");
index b737ffa61c8143b0b8116193760342bb7017cbdd..4a6c73b2371b6f6f05e5fbcb10b9eb929381c5e1 100644 (file)
@@ -474,9 +474,6 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
                        curproxy->uri_len_limit   = defproxy.uri_len_limit;
                        curproxy->uri_dirs_depth1 = defproxy.uri_dirs_depth1;
 
-                       if (defproxy.hh_name)
-                               curproxy->hh_name = strdup(defproxy.hh_name);
-                       curproxy->hh_len  = defproxy.hh_len;
                        curproxy->hh_match_domain  = defproxy.hh_match_domain;
 
                        if (defproxy.conn_src.iface_name)
@@ -622,7 +619,6 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
                free(defproxy.dyncookie_key);
                free(defproxy.cookie_domain);
                free(defproxy.lbprm.arg_str);
-               free(defproxy.hh_name);
                free(defproxy.capture_name);
                free(defproxy.monitor_uri);
                free(defproxy.defbe.name);