Commit 91cacbcc authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Let VTP hash the vrt_endpoint, and dont truncate the hash.

parent f44b0c31
...@@ -38,9 +38,7 @@ ...@@ -38,9 +38,7 @@
#include "cache_varnishd.h" #include "cache_varnishd.h"
#include "vend.h"
#include "vsa.h" #include "vsa.h"
#include "vsha256.h"
#include "vtcp.h" #include "vtcp.h"
#include "vtim.h" #include "vtim.h"
...@@ -555,27 +553,6 @@ VRT_backend_vsm_need(VRT_CTX) ...@@ -555,27 +553,6 @@ VRT_backend_vsm_need(VRT_CTX)
return (VRT_VSC_Overhead(VSC_vbe_size)); return (VRT_VSC_Overhead(VSC_vbe_size));
} }
static uint64_t
vrt_hash_be(const struct vrt_endpoint *vep)
{
struct VSHA256Context cx[1];
unsigned char ident[VSHA256_DIGEST_LENGTH];
CHECK_OBJ_NOTNULL(vep, VRT_ENDPOINT_MAGIC);
VSHA256_Init(cx);
VSHA256_Update(cx, vbe_proto_ident, strlen(vbe_proto_ident));
if (vep->ipv4 != NULL)
VSHA256_Update(cx, vep->ipv4, vsa_suckaddr_len);
if (vep->ipv6 != NULL)
VSHA256_Update(cx, vep->ipv6, vsa_suckaddr_len);
if (vep->uds_path != NULL)
VSHA256_Update(cx, vep->uds_path, strlen(vep->uds_path));
if (vep->ident != NULL)
VSHA256_Update(cx, vep->ident, vep->ident_len);
VSHA256_Final(ident, cx);
return (vbe64dec(ident));
}
VCL_BACKEND VCL_BACKEND
VRT_new_backend_clustered(VRT_CTX, struct vsmw_cluster *vc, VRT_new_backend_clustered(VRT_CTX, struct vsmw_cluster *vc,
const struct vrt_backend *vrt) const struct vrt_backend *vrt)
...@@ -634,8 +611,7 @@ VRT_new_backend_clustered(VRT_CTX, struct vsmw_cluster *vc, ...@@ -634,8 +611,7 @@ VRT_new_backend_clustered(VRT_CTX, struct vsmw_cluster *vc,
if (! vcl->temp->is_warm) if (! vcl->temp->is_warm)
VRT_VSC_Hide(be->vsc_seg); VRT_VSC_Hide(be->vsc_seg);
be->tcp_pool = VTP_Ref(vep->ipv4, vep->ipv6, be->tcp_pool = VTP_Ref(vep, vbe_proto_ident);
vep->uds_path, vrt_hash_be(vrt->endpoint));
AN(be->tcp_pool); AN(be->tcp_pool);
vbp = vrt->probe; vbp = vrt->probe;
......
...@@ -37,7 +37,9 @@ ...@@ -37,7 +37,9 @@
#include "cache_varnishd.h" #include "cache_varnishd.h"
#include "vend.h"
#include "vsa.h" #include "vsa.h"
#include "vsha256.h"
#include "vtcp.h" #include "vtcp.h"
#include "vus.h" #include "vus.h"
#include "vtim.h" #include "vtim.h"
...@@ -85,7 +87,7 @@ struct conn_pool { ...@@ -85,7 +87,7 @@ struct conn_pool {
const struct cp_methods *methods; const struct cp_methods *methods;
uintmax_t id; char ident[VSHA256_DIGEST_LENGTH];
void *priv; void *priv;
VTAILQ_ENTRY(conn_pool) list; VTAILQ_ENTRY(conn_pool) list;
...@@ -201,14 +203,14 @@ vcp_handle(struct waited *w, enum wait_event ev, vtim_real now) ...@@ -201,14 +203,14 @@ vcp_handle(struct waited *w, enum wait_event ev, vtim_real now)
*/ */
static struct conn_pool * static struct conn_pool *
VCP_Ref(uintmax_t id) VCP_Ref(const uint8_t *ident)
{ {
struct conn_pool *cp; struct conn_pool *cp;
Lck_Lock(&conn_pools_mtx); Lck_Lock(&conn_pools_mtx);
VTAILQ_FOREACH(cp, &conn_pools, list) { VTAILQ_FOREACH(cp, &conn_pools, list) {
assert(cp->refcnt > 0); assert(cp->refcnt > 0);
if (cp->id != id) if (memcmp(ident, cp->ident, sizeof cp->ident))
continue; continue;
cp->refcnt++; cp->refcnt++;
Lck_Unlock(&conn_pools_mtx); Lck_Unlock(&conn_pools_mtx);
...@@ -222,8 +224,8 @@ VCP_Ref(uintmax_t id) ...@@ -222,8 +224,8 @@ VCP_Ref(uintmax_t id)
*/ */
static void * static void *
VCP_New(struct conn_pool *cp, uintmax_t id, void *priv, VCP_New(struct conn_pool *cp, uint8_t ident[VSHA256_DIGEST_LENGTH],
const struct cp_methods *cm) void *priv, const struct cp_methods *cm)
{ {
AN(cp); AN(cp);
...@@ -232,7 +234,7 @@ VCP_New(struct conn_pool *cp, uintmax_t id, void *priv, ...@@ -232,7 +234,7 @@ VCP_New(struct conn_pool *cp, uintmax_t id, void *priv,
AN(cm->close); AN(cm->close);
INIT_OBJ(cp, CONN_POOL_MAGIC); INIT_OBJ(cp, CONN_POOL_MAGIC);
cp->id = id; memcpy(cp->ident, ident, sizeof cp->ident);
cp->priv = priv; cp->priv = priv;
cp->methods = cm; cp->methods = cm;
cp->refcnt = 1; cp->refcnt = 1;
...@@ -672,31 +674,41 @@ static const struct cp_methods vus_methods = { ...@@ -672,31 +674,41 @@ static const struct cp_methods vus_methods = {
*/ */
struct tcp_pool * struct tcp_pool *
VTP_Ref(const struct suckaddr *ip4, const struct suckaddr *ip6, const char *uds, VTP_Ref(const struct vrt_endpoint *vep, const char *ident)
uintmax_t id)
{ {
struct tcp_pool *tp; struct tcp_pool *tp;
struct conn_pool *cp; struct conn_pool *cp;
const struct cp_methods *methods; const struct cp_methods *methods;
struct VSHA256Context cx[1];
assert((uds != NULL && ip4 == NULL && ip6 == NULL) || unsigned char digest[VSHA256_DIGEST_LENGTH];
(uds == NULL && (ip4 != NULL || ip6 != NULL)));
CHECK_OBJ_NOTNULL(vep, VRT_ENDPOINT_MAGIC);
cp = VCP_Ref(id); AN(ident);
if (cp != NULL) { VSHA256_Init(cx);
tp = cp->priv; VSHA256_Update(cx, ident, strlen(ident) + 1); // include \0
CHECK_OBJ_NOTNULL(tp, TCP_POOL_MAGIC); if (vep->uds_path != NULL) {
AZ(vep->ipv4);
if (uds != NULL) { AZ(vep->ipv6);
AN(tp->uds); VSHA256_Update(cx, "UDS", 4); // include \0
AZ(strcmp(tp->uds, uds)); VSHA256_Update(cx, vep->uds_path, strlen(vep->uds_path));
} else {
assert(vep->ipv4 != NULL || vep->ipv6 != NULL);
if (vep->ipv4 != NULL) {
assert(VSA_Sane(vep->ipv4));
VSHA256_Update(cx, "IP4", 4); // include \0
VSHA256_Update(cx, vep->ipv4, vsa_suckaddr_len);
}
if (vep->ipv6 != NULL) {
assert(VSA_Sane(vep->ipv6));
VSHA256_Update(cx, "IP6", 4); // include \0
VSHA256_Update(cx, vep->ipv6, vsa_suckaddr_len);
} }
if (ip4 != NULL)
AZ(VSA_Compare(tp->ip4, ip4));
if (ip6 != NULL)
AZ(VSA_Compare(tp->ip6, ip6));
return (cp->priv);
} }
VSHA256_Final(digest, cx);
cp = VCP_Ref(digest);
if (cp != NULL)
return (cp->priv);
/* /*
* this is racy - we could end up with additional pools on the same id * this is racy - we could end up with additional pools on the same id
...@@ -704,18 +716,19 @@ VTP_Ref(const struct suckaddr *ip4, const struct suckaddr *ip6, const char *uds, ...@@ -704,18 +716,19 @@ VTP_Ref(const struct suckaddr *ip4, const struct suckaddr *ip6, const char *uds,
*/ */
ALLOC_OBJ(tp, TCP_POOL_MAGIC); ALLOC_OBJ(tp, TCP_POOL_MAGIC);
AN(tp); AN(tp);
if (uds != NULL) { if (vep->uds_path != NULL) {
methods = &vus_methods; methods = &vus_methods;
tp->uds = strdup(uds); tp->uds = strdup(vep->uds_path);
AN(tp->uds);
} }
else { else {
methods = &vtp_methods; methods = &vtp_methods;
if (ip4 != NULL) if (vep->ipv4 != NULL)
tp->ip4 = VSA_Clone(ip4); tp->ip4 = VSA_Clone(vep->ipv4);
if (ip6 != NULL) if (vep->ipv6 != NULL)
tp->ip6 = VSA_Clone(ip6); tp->ip6 = VSA_Clone(vep->ipv6);
} }
return (VCP_New(tp->cp, id, tp, methods)); return (VCP_New(tp->cp, digest, tp, methods));
} }
/*-------------------------------------------------------------------- /*--------------------------------------------------------------------
...@@ -824,7 +837,9 @@ VTP_panic(struct vsb *vsb, struct tcp_pool *tp) ...@@ -824,7 +837,9 @@ VTP_panic(struct vsb *vsb, struct tcp_pool *tp)
if (PAN_dump_struct(vsb, tp, TCP_POOL_MAGIC, "tcp_pool")) if (PAN_dump_struct(vsb, tp, TCP_POOL_MAGIC, "tcp_pool"))
return; return;
VSB_printf(vsb, "id = 0x%jx,\n", tp->cp->id); VSB_printf(vsb, "ident = ");
VSB_quote(vsb, tp->cp->ident, VSHA256_DIGEST_LENGTH, VSB_QUOTE_HEX);
VSB_printf(vsb, ",\n");
if (tp->uds) if (tp->uds)
VSB_printf(vsb, "uds = %s,\n", tp->uds); VSB_printf(vsb, "uds = %s,\n", tp->uds);
if (tp->ip4 && VSA_Sane(tp->ip4)) { if (tp->ip4 && VSA_Sane(tp->ip4)) {
......
...@@ -54,13 +54,12 @@ void PFD_RemoteName(const struct pfd *, char *, unsigned, char *, unsigned); ...@@ -54,13 +54,12 @@ void PFD_RemoteName(const struct pfd *, char *, unsigned, char *, unsigned);
struct VSC_vbe; struct VSC_vbe;
struct tcp_pool *VTP_Ref(const struct suckaddr *ip4, const struct suckaddr *ip6, struct tcp_pool *VTP_Ref(const struct vrt_endpoint *, const char *ident);
const char *uds, uintmax_t id);
/* /*
* Get a reference to a TCP pool. Either one or both of ip4 or * Get a reference to a TCP pool. Either one or both of ipv4 or
* ip6 arg must be non-NULL, or uds must be non-NULL. If recycling * ipv6 arg must be non-NULL, or uds must be non-NULL. If recycling
* is to be used, the id pointer distinguishes the pool per * is to be used, the ident pointer distinguishes the pool from
* protocol. * other pools with same {ipv4, ipv6, uds}.
*/ */
void VTP_AddRef(struct tcp_pool *); void VTP_AddRef(struct tcp_pool *);
......
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