Commit ec4eb07c authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Hash on both URL and Host header. If no host header, hash on URL twice.


git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@454 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 9f4b7c2a
...@@ -233,11 +233,11 @@ fetch_eof(struct sess *sp, int fd, struct http *hp) ...@@ -233,11 +233,11 @@ fetch_eof(struct sess *sp, int fd, struct http *hp)
int int
FetchBody(struct worker *w, struct sess *sp) FetchBody(struct worker *w, struct sess *sp)
{ {
int i, cls; int cls;
struct vbe_conn *vc; struct vbe_conn *vc;
struct http *hp; struct http *hp;
char *b; char *b;
int body; int body = 1; /* XXX */
vc = sp->vbc; vc = sp->vbc;
hp = sp->bkd_http; hp = sp->bkd_http;
...@@ -278,11 +278,9 @@ FetchBody(struct worker *w, struct sess *sp) ...@@ -278,11 +278,9 @@ FetchBody(struct worker *w, struct sess *sp)
int int
FetchHeaders(struct worker *w, struct sess *sp) FetchHeaders(struct worker *w, struct sess *sp)
{ {
int i, cls; int i;
struct vbe_conn *vc; struct vbe_conn *vc;
struct http *hp; struct http *hp;
char *b;
int body;
sp->obj->xid = sp->xid; sp->obj->xid = sp->xid;
......
...@@ -20,7 +20,7 @@ HSH_Lookup(struct worker *w, struct http *h) ...@@ -20,7 +20,7 @@ HSH_Lookup(struct worker *w, struct http *h)
{ {
struct objhead *oh; struct objhead *oh;
struct object *o; struct object *o;
char *b; char *b, *c;
assert(hash != NULL); assert(hash != NULL);
/* Precreate an objhead and object in case we need them */ /* Precreate an objhead and object in case we need them */
...@@ -41,7 +41,9 @@ HSH_Lookup(struct worker *w, struct http *h) ...@@ -41,7 +41,9 @@ HSH_Lookup(struct worker *w, struct http *h)
} }
assert(http_GetURL(h, &b)); assert(http_GetURL(h, &b));
oh = hash->lookup(b, w->nobjhead); if (!http_GetHdr(h, "Host", &c))
c = b;
oh = hash->lookup(b, c, w->nobjhead);
if (oh == w->nobjhead) if (oh == w->nobjhead)
w->nobjhead = NULL; w->nobjhead = NULL;
AZ(pthread_mutex_lock(&oh->mtx)); AZ(pthread_mutex_lock(&oh->mtx));
......
...@@ -17,7 +17,8 @@ ...@@ -17,7 +17,8 @@
struct hcl_entry { struct hcl_entry {
TAILQ_ENTRY(hcl_entry) list; TAILQ_ENTRY(hcl_entry) list;
char *key; char *key1;
char *key2;
struct objhead *obj; struct objhead *obj;
unsigned refcnt; unsigned refcnt;
unsigned hash; unsigned hash;
...@@ -97,7 +98,7 @@ hcl_start(void) ...@@ -97,7 +98,7 @@ hcl_start(void)
*/ */
static struct objhead * static struct objhead *
hcl_lookup(const char *key, struct objhead *nobj) hcl_lookup(const char *key1, const char *key2, struct objhead *nobj)
{ {
struct hcl_entry *he, *he2; struct hcl_entry *he, *he2;
MD5_CTX c; MD5_CTX c;
...@@ -106,7 +107,9 @@ hcl_lookup(const char *key, struct objhead *nobj) ...@@ -106,7 +107,9 @@ hcl_lookup(const char *key, struct objhead *nobj)
int i; int i;
MD5Init(&c); MD5Init(&c);
MD5Update(&c, key, strlen(key)); MD5Update(&c, key1, strlen(key1));
MD5Update(&c, "", 1);
MD5Update(&c, key2, strlen(key2));
MD5Final(md5, &c); MD5Final(md5, &c);
memcpy(&u1, md5, sizeof u1); memcpy(&u1, md5, sizeof u1);
u1 %= hcl_nhash; u1 %= hcl_nhash;
...@@ -115,21 +118,25 @@ hcl_lookup(const char *key, struct objhead *nobj) ...@@ -115,21 +118,25 @@ hcl_lookup(const char *key, struct objhead *nobj)
AZ(pthread_mutex_lock(&hcl_mutex[u2])); AZ(pthread_mutex_lock(&hcl_mutex[u2]));
TAILQ_FOREACH(he, &hcl_head[u1], list) { TAILQ_FOREACH(he, &hcl_head[u1], list) {
i = strcmp(key, he->key); i = strcmp(key1, he->key1);
if (i < 0) if (i < 0)
continue; continue;
if (i == 0) { if (i > 0)
he->refcnt++; break;
nobj = he->obj; i = strcmp(key2, he->key2);
nobj->hashpriv = he; if (i < 0)
AZ(pthread_mutex_unlock(&hcl_mutex[u2])); continue;
return (nobj); if (i > 0)
} break;
if (nobj == NULL) { he->refcnt++;
AZ(pthread_mutex_unlock(&hcl_mutex[u2])); nobj = he->obj;
return (NULL); nobj->hashpriv = he;
} AZ(pthread_mutex_unlock(&hcl_mutex[u2]));
break; return (nobj);
}
if (nobj == NULL) {
AZ(pthread_mutex_unlock(&hcl_mutex[u2]));
return (NULL);
} }
he2 = calloc(sizeof *he2, 1); he2 = calloc(sizeof *he2, 1);
assert(he2 != NULL); assert(he2 != NULL);
...@@ -137,8 +144,10 @@ hcl_lookup(const char *key, struct objhead *nobj) ...@@ -137,8 +144,10 @@ hcl_lookup(const char *key, struct objhead *nobj)
he2->refcnt = 1; he2->refcnt = 1;
he2->hash = u1; he2->hash = u1;
he2->mtx = u2; he2->mtx = u2;
he2->key = strdup(key); he2->key1 = strdup(key1);
assert(he2->key != NULL); assert(he2->key1 != NULL);
he2->key2 = strdup(key2);
assert(he2->key2 != NULL);
nobj->hashpriv = he2; nobj->hashpriv = he2;
if (he != NULL) if (he != NULL)
TAILQ_INSERT_BEFORE(he, he2, list); TAILQ_INSERT_BEFORE(he, he2, list);
...@@ -164,7 +173,8 @@ hcl_deref(struct objhead *obj) ...@@ -164,7 +173,8 @@ hcl_deref(struct objhead *obj)
mtx = he->mtx; mtx = he->mtx;
AZ(pthread_mutex_lock(&hcl_mutex[mtx])); AZ(pthread_mutex_lock(&hcl_mutex[mtx]));
if (--he->refcnt == 0) { if (--he->refcnt == 0) {
free(he->key); free(he->key1);
free(he->key2);
TAILQ_REMOVE(&hcl_head[he->hash], he, list); TAILQ_REMOVE(&hcl_head[he->hash], he, list);
free(he); free(he);
ret = 0; ret = 0;
......
...@@ -15,7 +15,8 @@ ...@@ -15,7 +15,8 @@
struct hsl_entry { struct hsl_entry {
TAILQ_ENTRY(hsl_entry) list; TAILQ_ENTRY(hsl_entry) list;
char *key; char *key1;
char *key2;
struct objhead *obj; struct objhead *obj;
unsigned refcnt; unsigned refcnt;
}; };
...@@ -43,35 +44,41 @@ hsl_start(void) ...@@ -43,35 +44,41 @@ hsl_start(void)
*/ */
static struct objhead * static struct objhead *
hsl_lookup(const char *key, struct objhead *nobj) hsl_lookup(const char *key1, const char *key2, struct objhead *nobj)
{ {
struct hsl_entry *he, *he2; struct hsl_entry *he, *he2;
int i; int i;
AZ(pthread_mutex_lock(&hsl_mutex)); AZ(pthread_mutex_lock(&hsl_mutex));
TAILQ_FOREACH(he, &hsl_head, list) { TAILQ_FOREACH(he, &hsl_head, list) {
i = strcmp(key, he->key); i = strcmp(key1, he->key1);
if (i < 0) if (i < 0)
continue; continue;
if (i == 0) { if (i > 0)
he->refcnt++; break;
nobj = he->obj; i = strcmp(key2, he->key2);
nobj->hashpriv = he; if (i < 0)
AZ(pthread_mutex_unlock(&hsl_mutex)); continue;
return (nobj); if (i > 0)
} break;
if (nobj == NULL) { he->refcnt++;
AZ(pthread_mutex_unlock(&hsl_mutex)); nobj = he->obj;
return (NULL); nobj->hashpriv = he;
} AZ(pthread_mutex_unlock(&hsl_mutex));
break; return (nobj);
}
if (nobj == NULL) {
AZ(pthread_mutex_unlock(&hsl_mutex));
return (NULL);
} }
he2 = calloc(sizeof *he2, 1); he2 = calloc(sizeof *he2, 1);
assert(he2 != NULL); assert(he2 != NULL);
he2->obj = nobj; he2->obj = nobj;
he2->refcnt = 1; he2->refcnt = 1;
he2->key = strdup(key); he2->key1 = strdup(key1);
assert(he2->key != NULL); assert(he2->key1 != NULL);
he2->key2 = strdup(key2);
assert(he2->key2 != NULL);
nobj->hashpriv = he2; nobj->hashpriv = he2;
if (he != NULL) if (he != NULL)
TAILQ_INSERT_BEFORE(he, he2, list); TAILQ_INSERT_BEFORE(he, he2, list);
...@@ -95,7 +102,8 @@ hsl_deref(struct objhead *obj) ...@@ -95,7 +102,8 @@ hsl_deref(struct objhead *obj)
he = obj->hashpriv; he = obj->hashpriv;
AZ(pthread_mutex_lock(&hsl_mutex)); AZ(pthread_mutex_lock(&hsl_mutex));
if (--he->refcnt == 0) { if (--he->refcnt == 0) {
free(he->key); free(he->key1);
free(he->key2);
TAILQ_REMOVE(&hsl_head, he, list); TAILQ_REMOVE(&hsl_head, he, list);
free(he); free(he);
ret = 0; ret = 0;
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
typedef int hash_init_f(const char *); typedef int hash_init_f(const char *);
typedef void hash_start_f(void); typedef void hash_start_f(void);
typedef struct objhead *hash_lookup_f(const char *key, struct objhead *nobj); typedef struct objhead *hash_lookup_f(const char *key1, const char *key2, struct objhead *nobj);
typedef int hash_deref_f(struct objhead *obj); typedef int hash_deref_f(struct objhead *obj);
struct hash_slinger { struct hash_slinger {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment