From: Aurelien DARRAGON Date: Wed, 11 Oct 2023 09:35:48 +0000 (+0200) Subject: MINOR: lbprm: compute the hash avalanche in gen_hash() X-Git-Tag: v2.9-dev8~58 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=08767e162d876e3eb5537df26638ab8a32c88ddf;p=thirdparty%2Fhaproxy.git MINOR: lbprm: compute the hash avalanche in gen_hash() 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. --- diff --git a/src/backend.c b/src/backend.c index e7e8d29ed7..809d922271 100644 --- a/src/backend.c +++ b/src/backend.c @@ -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);