[master] 22600aa Add an official VSA_Clone() function.
Poul-Henning Kamp
phk at FreeBSD.org
Fri Jan 9 15:54:29 CET 2015
commit 22600aac910468a646f3f529d51f30649b5fc730
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Thu Jan 8 07:27:01 2015 +0000
Add an official VSA_Clone() function.
diff --git a/bin/varnishd/cache/cache_backend_cfg.c b/bin/varnishd/cache/cache_backend_cfg.c
index db45f75..432ff05 100644
--- a/bin/varnishd/cache/cache_backend_cfg.c
+++ b/bin/varnishd/cache/cache_backend_cfg.c
@@ -155,21 +155,6 @@ VBE_DropRefConn(struct backend *b, const struct acct_bereq *acct_bereq)
}
/*--------------------------------------------------------------------
- * See lib/libvcc/vcc_backend.c::emit_sockaddr()
- */
-
-static void
-copy_sockaddr(struct suckaddr **sa, const struct suckaddr *src)
-{
-
- assert(VSA_Sane(src));
- *sa = calloc(1, vsa_suckaddr_len);
- XXXAN(*sa);
- memcpy(*sa, src, vsa_suckaddr_len);
- assert(VSA_Sane(*sa));
-}
-
-/*--------------------------------------------------------------------
* Add a backend/director instance when loading a VCL.
* If an existing backend is matched, grab a refcount and return.
* Else create a new backend structure with reference initialized to one.
@@ -232,9 +217,9 @@ VBE_AddBackend(struct cli *cli, const struct vrt_backend *vb)
* Copy over the sockaddrs
*/
if (vb->ipv4_suckaddr != NULL)
- copy_sockaddr(&b->ipv4, vb->ipv4_suckaddr);
+ b->ipv4 = VSA_Clone(vb->ipv4_suckaddr);
if (vb->ipv6_suckaddr != NULL)
- copy_sockaddr(&b->ipv6, vb->ipv6_suckaddr);
+ b->ipv6 = VSA_Clone(vb->ipv6_suckaddr);
assert(b->ipv4 != NULL || b->ipv6 != NULL);
diff --git a/include/vsa.h b/include/vsa.h
index 26f6419..8496278 100644
--- a/include/vsa.h
+++ b/include/vsa.h
@@ -37,6 +37,7 @@ int VSA_Sane(const struct suckaddr *);
socklen_t VSA_Len(const struct suckaddr *);
unsigned VSA_Port(const struct suckaddr *);
int VSA_Compare(const struct suckaddr *, const struct suckaddr *);
+struct suckaddr *VSA_Clone(const struct suckaddr *sua);
const struct sockaddr *VSA_Get_Sockaddr(const struct suckaddr *, socklen_t *sl);
diff --git a/lib/libvarnish/vsa.c b/lib/libvarnish/vsa.c
index c2838d6..7057487 100644
--- a/lib/libvarnish/vsa.c
+++ b/lib/libvarnish/vsa.c
@@ -323,6 +323,18 @@ VSA_Compare(const struct suckaddr *sua1, const struct suckaddr *sua2)
return (memcmp(sua1, sua2, vsa_suckaddr_len));
}
+struct suckaddr *
+VSA_Clone(const struct suckaddr *sua)
+{
+ struct suckaddr *sua2;
+
+ assert(VSA_Sane(sua));
+ sua2 = calloc(1, vsa_suckaddr_len);
+ XXXAN(sua2);
+ memcpy(sua2, sua, vsa_suckaddr_len);
+ return (sua2);
+}
+
unsigned
VSA_Port(const struct suckaddr *sua)
{
More information about the varnish-commit
mailing list