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

Add VRT_Endpoint_Clone() and give backends a copy of the endpoint

information to make them easier to clone.
parent 94af15e8
......@@ -438,6 +438,7 @@ vbe_free(struct backend *be)
VRT_BACKEND_HANDLE();
#undef DA
#undef DN
free(be->endpoint);
Lck_Delete(&be->mtx);
FREE_OBJ(be);
......@@ -588,6 +589,8 @@ VRT_new_backend_clustered(VRT_CTX, struct vsmw_cluster *vc,
return (NULL);
Lck_New(&be->mtx, lck_backend);
be->endpoint = VRT_Endpoint_Clone(vrt->endpoint);
vep = be->endpoint;
#define DA(x) do { if (vrt->x != NULL) REPLACE((be->x), (vrt->x)); } while (0)
#define DN(x) do { be->x = vrt->x; } while (0)
VRT_BACKEND_HANDLE();
......
......@@ -57,6 +57,8 @@ struct backend {
VTAILQ_ENTRY(backend) list;
struct lock mtx;
struct vrt_endpoint *endpoint;
VRT_BACKEND_FIELDS()
unsigned sick;
......
......@@ -33,6 +33,8 @@
#include "config.h"
#include <stdlib.h>
#include "cache_varnishd.h"
#include "cache_objhead.h"
......@@ -1061,3 +1063,47 @@ VRT_Format_Proxy(struct vsb *vsb, VCL_INT version, VCL_IP sac, VCL_IP sas,
{
VPX_Format_Proxy(vsb, (int)version, sac, sas, auth);
}
/*
* Clone a struct vrt_endpoint in a single malloc() allocation
*/
struct vrt_endpoint *
VRT_Endpoint_Clone(const struct vrt_endpoint *vep)
{
size_t sz;
struct vrt_endpoint *nvep;
struct suckaddr *sa;
char *p;
CHECK_OBJ_NOTNULL(vep, VRT_ENDPOINT_MAGIC);
sz = sizeof *nvep;
if (vep->ipv4)
sz += vsa_suckaddr_len;
if (vep->ipv6)
sz += vsa_suckaddr_len;
if (vep->uds_path != NULL)
sz += strlen(vep->uds_path) + 1;
p = malloc(sz);
AN(p);
nvep = (void*)p;
p += sizeof *nvep;
INIT_OBJ(nvep, VRT_ENDPOINT_MAGIC);
if (vep->ipv4) {
sa = (void*)p; //lint !e826
memcpy(sa, vep->ipv4, vsa_suckaddr_len); //lint !e826
nvep->ipv4 = sa;
p += vsa_suckaddr_len;
}
if (vep->ipv6) {
sa = (void*)p; //lint !e826
memcpy(sa, vep->ipv6, vsa_suckaddr_len); //lint !e826
nvep->ipv6 = sa;
p += vsa_suckaddr_len;
}
if (vep->uds_path != NULL) {
strcpy(p, vep->uds_path);
nvep->uds_path = p;
}
return (nvep);
}
......@@ -53,8 +53,9 @@
* binary/load-time compatible, increment MAJOR version
*
* 13.0 (2021-03-15)
* VRT_Endpoint_Clone() added.
* Calling convention for VDP implementation changed
* Added VRT_ValidHdr()
* VRT_ValidHdr() added.
* struct vmod_priv_methods added
* struct vmod_priv free member replaced with methods
* VRT_CTX_Assert() added
......@@ -521,6 +522,7 @@ VCL_BACKEND VRT_new_backend_clustered(VRT_CTX,
struct vsmw_cluster *, const struct vrt_backend *);
size_t VRT_backend_vsm_need(VRT_CTX);
void VRT_delete_backend(VRT_CTX, VCL_BACKEND *);
struct vrt_endpoint *VRT_Endpoint_Clone(const struct vrt_endpoint *vep);
/* VSM related */
struct vsmw_cluster *VRT_VSM_Cluster_New(VRT_CTX, size_t);
......
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