]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: lbprm: compute the hash avalanche in gen_hash()
authorAurelien DARRAGON <adarragon@haproxy.com>
Wed, 11 Oct 2023 09:35:48 +0000 (11:35 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 13 Oct 2023 08:05:06 +0000 (10:05 +0200)
Instead of systematically computing the avalanche hash right after the
gen_hash() call, do it inside the gen_hash() function directly to ensure
avalanche setting is always considered.

src/backend.c

index e7e8d29ed7e0699fbd7e2620cdb5a5e2e291ee07..809d922271008a7d640c8f9aa7f8c32444e82929 100644 (file)
@@ -99,6 +99,9 @@ static unsigned int gen_hash(const struct proxy* px, const char* key, unsigned l
                break;
        }
 
+       if ((px->lbprm.algo & BE_LB_HASH_MOD) == BE_LB_HMOD_AVAL)
+               hash = full_hash(hash);
+
        return hash;
 }
 
@@ -190,6 +193,10 @@ static struct server *get_server_sh(struct proxy *px, const char *addr, int len,
                h ^= ntohl(*(unsigned int *)(&addr[l]));
                l += sizeof (int);
        }
+       /* FIXME: why don't we use gen_hash() here as well?
+        * -> we don't take into account hash function from "hash_type"
+        * options here..
+        */
        if ((px->lbprm.algo & BE_LB_HASH_MOD) == BE_LB_HMOD_AVAL)
                h = full_hash(h);
  hash_done:
@@ -245,8 +252,6 @@ static struct server *get_server_uh(struct proxy *px, char *uri, int uri_len, co
 
        hash = gen_hash(px, start, (end - start));
 
-       if ((px->lbprm.algo & BE_LB_HASH_MOD) == BE_LB_HMOD_AVAL)
-               hash = full_hash(hash);
  hash_done:
        if ((px->lbprm.algo & BE_LB_LKUP) == BE_LB_LKUP_CHTREE)
                return chash_get_server_hash(px, hash, avoid);
@@ -302,9 +307,6 @@ static struct server *get_server_ph(struct proxy *px, const char *uri, int uri_l
                                }
                                hash = gen_hash(px, start, (end - start));
 
-                               if ((px->lbprm.algo & BE_LB_HASH_MOD) == BE_LB_HMOD_AVAL)
-                                       hash = full_hash(hash);
-
                                if ((px->lbprm.algo & BE_LB_LKUP) == BE_LB_LKUP_CHTREE)
                                        return chash_get_server_hash(px, hash, avoid);
                                else
@@ -382,9 +384,6 @@ static struct server *get_server_ph_post(struct stream *s, const struct server *
                                }
                                hash = gen_hash(px, start, (end - start));
 
-                               if ((px->lbprm.algo & BE_LB_HASH_MOD) == BE_LB_HMOD_AVAL)
-                                       hash = full_hash(hash);
-
                                if ((px->lbprm.algo & BE_LB_LKUP) == BE_LB_LKUP_CHTREE)
                                        return chash_get_server_hash(px, hash, avoid);
                                else
@@ -477,8 +476,7 @@ static struct server *get_server_hh(struct stream *s, const struct server *avoid
                start = p;
                hash = gen_hash(px, start, (end - start));
        }
-       if ((px->lbprm.algo & BE_LB_HASH_MOD) == BE_LB_HMOD_AVAL)
-               hash = full_hash(hash);
+
  hash_done:
        if ((px->lbprm.algo & BE_LB_LKUP) == BE_LB_LKUP_CHTREE)
                return chash_get_server_hash(px, hash, avoid);
@@ -522,8 +520,6 @@ static struct server *get_server_rch(struct stream *s, const struct server *avoi
         */
        hash = gen_hash(px, smp.data.u.str.area, len);
 
-       if ((px->lbprm.algo & BE_LB_HASH_MOD) == BE_LB_HMOD_AVAL)
-               hash = full_hash(hash);
  hash_done:
        if ((px->lbprm.algo & BE_LB_LKUP) == BE_LB_LKUP_CHTREE)
                return chash_get_server_hash(px, hash, avoid);
@@ -556,8 +552,6 @@ static struct server *get_server_expr(struct stream *s, const struct server *avo
         */
        hash = gen_hash(px, smp->data.u.str.area, smp->data.u.str.data);
 
-       if ((px->lbprm.algo & BE_LB_HASH_MOD) == BE_LB_HMOD_AVAL)
-               hash = full_hash(hash);
  hash_done:
        if ((px->lbprm.algo & BE_LB_LKUP) == BE_LB_LKUP_CHTREE)
                return chash_get_server_hash(px, hash, avoid);