|
From 82456753cae9200aa1f4031f64c22c08e130f072 Mon Sep 17 00:00:00 2001
|
|
From: Dan Dubovik <ddubovik@godaddy.com>
|
|
Date: Tue, 8 Jul 2014 08:51:03 -0700
|
|
Subject: [PATCH 21/21] BUG/MEDIUM: backend: Update hash to use unsigned int
|
|
throughout
|
|
|
|
When we were generating a hash, it was done using an unsigned long. When the hash was used
|
|
to select a backend, it was sent as an unsigned int. This made it difficult to predict which
|
|
backend would be selected.
|
|
|
|
This patch updates get_hash, and the hash methods to use an unsigned int, to remain consistent
|
|
throughout the codebase.
|
|
|
|
This fix should be backported to 1.5 and probably in part to 1.4.
|
|
(cherry picked from commit bd57a9f977f60fcf7818f462953da3740e3bd010)
|
|
---
|
|
include/common/hash.h | 6 +++---
|
|
src/backend.c | 14 +++++++-------
|
|
src/hash.c | 10 +++++-----
|
|
3 files changed, 15 insertions(+), 15 deletions(-)
|
|
|
|
diff --git a/include/common/hash.h b/include/common/hash.h
|
|
index 379bf89..7039ba5 100644
|
|
--- a/include/common/hash.h
|
|
+++ b/include/common/hash.h
|
|
@@ -22,8 +22,8 @@
|
|
#ifndef _COMMON_HASH_H_
|
|
#define _COMMON_HASH_H_
|
|
|
|
-unsigned long hash_djb2(const char *key, int len);
|
|
-unsigned long hash_wt6(const char *key, int len);
|
|
-unsigned long hash_sdbm(const char *key, int len);
|
|
+unsigned int hash_djb2(const char *key, int len);
|
|
+unsigned int hash_wt6(const char *key, int len);
|
|
+unsigned int hash_sdbm(const char *key, int len);
|
|
|
|
#endif /* _COMMON_HASH_H_ */
|
|
diff --git a/src/backend.c b/src/backend.c
|
|
index 5ddb88c..a96b767 100644
|
|
--- a/src/backend.c
|
|
+++ b/src/backend.c
|
|
@@ -63,9 +63,9 @@ int be_lastsession(const struct proxy *be)
|
|
}
|
|
|
|
/* helper function to invoke the correct hash method */
|
|
-static unsigned long gen_hash(const struct proxy* px, const char* key, unsigned long len)
|
|
+static unsigned int gen_hash(const struct proxy* px, const char* key, unsigned long len)
|
|
{
|
|
- unsigned long hash;
|
|
+ unsigned int hash;
|
|
|
|
switch (px->lbprm.algo & BE_LB_HASH_FUNC) {
|
|
case BE_LB_HFCN_DJB2:
|
|
@@ -183,7 +183,7 @@ struct server *get_server_sh(struct proxy *px, const char *addr, int len)
|
|
*/
|
|
struct server *get_server_uh(struct proxy *px, char *uri, int uri_len)
|
|
{
|
|
- unsigned long hash = 0;
|
|
+ unsigned int hash = 0;
|
|
int c;
|
|
int slashes = 0;
|
|
const char *start, *end;
|
|
@@ -232,7 +232,7 @@ struct server *get_server_uh(struct proxy *px, char *uri, int uri_len)
|
|
*/
|
|
struct server *get_server_ph(struct proxy *px, const char *uri, int uri_len)
|
|
{
|
|
- unsigned long hash = 0;
|
|
+ unsigned int hash = 0;
|
|
const char *start, *end;
|
|
const char *p;
|
|
const char *params;
|
|
@@ -294,7 +294,7 @@ struct server *get_server_ph(struct proxy *px, const char *uri, int uri_len)
|
|
*/
|
|
struct server *get_server_ph_post(struct session *s)
|
|
{
|
|
- unsigned long hash = 0;
|
|
+ unsigned int hash = 0;
|
|
struct http_txn *txn = &s->txn;
|
|
struct channel *req = s->req;
|
|
struct http_msg *msg = &txn->req;
|
|
@@ -372,7 +372,7 @@ struct server *get_server_ph_post(struct session *s)
|
|
*/
|
|
struct server *get_server_hh(struct session *s)
|
|
{
|
|
- unsigned long hash = 0;
|
|
+ unsigned int hash = 0;
|
|
struct http_txn *txn = &s->txn;
|
|
struct proxy *px = s->be;
|
|
unsigned int plen = px->hh_len;
|
|
@@ -444,7 +444,7 @@ struct server *get_server_hh(struct session *s)
|
|
/* RDP Cookie HASH. */
|
|
struct server *get_server_rch(struct session *s)
|
|
{
|
|
- unsigned long hash = 0;
|
|
+ unsigned int hash = 0;
|
|
struct proxy *px = s->be;
|
|
unsigned long len;
|
|
int ret;
|
|
diff --git a/src/hash.c b/src/hash.c
|
|
index 034685e..aa236cb 100644
|
|
--- a/src/hash.c
|
|
+++ b/src/hash.c
|
|
@@ -17,7 +17,7 @@
|
|
#include <common/hash.h>
|
|
|
|
|
|
-unsigned long hash_wt6(const char *key, int len)
|
|
+unsigned int hash_wt6(const char *key, int len)
|
|
{
|
|
unsigned h0 = 0xa53c965aUL;
|
|
unsigned h1 = 0x5ca6953aUL;
|
|
@@ -44,9 +44,9 @@ unsigned long hash_wt6(const char *key, int len)
|
|
return h0 ^ h1;
|
|
}
|
|
|
|
-unsigned long hash_djb2(const char *key, int len)
|
|
+unsigned int hash_djb2(const char *key, int len)
|
|
{
|
|
- unsigned long hash = 5381;
|
|
+ unsigned int hash = 5381;
|
|
|
|
/* the hash unrolled eight times */
|
|
for (; len >= 8; len -= 8) {
|
|
@@ -72,9 +72,9 @@ unsigned long hash_djb2(const char *key, int len)
|
|
return hash;
|
|
}
|
|
|
|
-unsigned long hash_sdbm(const char *key, int len)
|
|
+unsigned int hash_sdbm(const char *key, int len)
|
|
{
|
|
- unsigned long hash = 0;
|
|
+ unsigned int hash = 0;
|
|
int c;
|
|
|
|
while (len--) {
|
|
--
|
|
1.8.5.5
|
|
|