[master] 6662b1b Pull the switch and give VCL_IP a proper type.
Poul-Henning Kamp
phk at varnish-cache.org
Mon Oct 28 09:10:33 CET 2013
commit 6662b1bbb8895f2961e6ed43393d9b6250b07e08
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Mon Oct 28 08:10:11 2013 +0000
Pull the switch and give VCL_IP a proper type.
diff --git a/include/vrt.h b/include/vrt.h
index cebe8e5..cab38de 100644
--- a/include/vrt.h
+++ b/include/vrt.h
@@ -56,8 +56,7 @@ typedef double VCL_DURATION;
typedef const char * VCL_ENUM;
typedef const char * VCL_HEADER;
typedef long VCL_INT;
-//typedef const struct suckaddr * VCL_IP;
-typedef const void * VCL_IP;
+typedef const struct suckaddr * VCL_IP;
typedef double VCL_REAL;
typedef const char * VCL_STRING;
typedef double VCL_TIME;
diff --git a/include/vsa.h b/include/vsa.h
index d21f3c0..26f6419 100644
--- a/include/vsa.h
+++ b/include/vsa.h
@@ -33,9 +33,9 @@
struct suckaddr;
extern const int vsa_suckaddr_len;
-int VSA_Sane(const void *);
-socklen_t VSA_Len(const void *);
-unsigned VSA_Port(const void *);
+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 *);
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 97ff0fa..4517549 100644
--- a/lib/libvarnish/vsa.c
+++ b/lib/libvarnish/vsa.c
@@ -252,9 +252,11 @@ VSA_Build(void *d, const void *s, unsigned sal)
default:
break;
}
- if (l != 0)
+ if (l != 0) {
memcpy(&sua->sa, s, l);
- return (sua);
+ return (sua);
+ }
+ return (NULL);
}
const struct sockaddr *
@@ -276,11 +278,10 @@ VSA_Get_Sockaddr(const struct suckaddr *sua, socklen_t *sl)
}
int
-VSA_Sane(const void *s)
+VSA_Sane(const struct suckaddr *s)
{
- const struct sockaddr *sa = s;
- switch(sa->sa_family) {
+ switch(s->sa.sa_family) {
case PF_INET:
case PF_INET6:
return (1);
@@ -290,17 +291,16 @@ VSA_Sane(const void *s)
}
socklen_t
-VSA_Len(const void *s)
+VSA_Len(const struct suckaddr *s)
{
- const struct sockaddr *sa = s;
- switch(sa->sa_family) {
+ switch(s->sa.sa_family) {
case PF_INET:
- return (sizeof(struct sockaddr_in));
+ return (sizeof(s->sa4));
case PF_INET6:
- return (sizeof(struct sockaddr_in6));
+ return (sizeof(s->sa6));
default:
- WRONG("Illegal socket family");
+ return (0);
}
}
@@ -313,22 +313,15 @@ VSA_Compare(const struct suckaddr *s1, const struct suckaddr *s2)
}
unsigned
-VSA_Port(const void *s)
+VSA_Port(const struct suckaddr *s)
{
- const struct sockaddr *sa = s;
- switch(sa->sa_family) {
+ switch(s->sa.sa_family) {
case PF_INET:
- {
- const struct sockaddr_in *ain = s;
- return (ntohs((ain->sin_port)));
- }
+ return (ntohs(s->sa4.sin_port));
case PF_INET6:
- {
- const struct sockaddr_in6 *ain = s;
- return (ntohs((ain->sin6_port)));
- }
+ return (ntohs(s->sa6.sin6_port));
default:
- WRONG("Illegal socket family");
+ return (0);
}
}
diff --git a/lib/libvmod_std/vmod_std_conversions.c b/lib/libvmod_std/vmod_std_conversions.c
index 42325d8..822bb75 100644
--- a/lib/libvmod_std/vmod_std_conversions.c
+++ b/lib/libvmod_std/vmod_std_conversions.c
@@ -127,7 +127,7 @@ VCL_IP
vmod_ip(const struct vrt_ctx *ctx, VCL_STRING s, VCL_IP d)
{
struct addrinfo hints, *res0 = NULL;
- const struct addrinfo *res, *best = NULL;
+ const struct addrinfo *res;
int error;
void *p;
struct suckaddr *r;
@@ -136,6 +136,10 @@ vmod_ip(const struct vrt_ctx *ctx, VCL_STRING s, VCL_IP d)
AN(d);
assert(VSA_Sane(d));
+ p = WS_Alloc(ctx->ws, vsa_suckaddr_len);
+ AN(p);
+ r = NULL;
+
if (s != NULL) {
memset(&hints, 0, sizeof(hints));
hints.ai_family = PF_UNSPEC;
@@ -143,19 +147,13 @@ vmod_ip(const struct vrt_ctx *ctx, VCL_STRING s, VCL_IP d)
error = getaddrinfo(s, "80", &hints, &res0);
if (!error) {
for (res = res0; res != NULL; res = res->ai_next) {
- if (VSA_Sane(res->ai_addr) &&
- res->ai_addrlen >= VSA_Len(res->ai_addr)) {
- best = res;
+ r = VSA_Build(p, res->ai_addr, res->ai_addrlen);
+ if (r != NULL)
break;
- }
}
}
}
- p = WS_Alloc(ctx->ws, vsa_suckaddr_len);
- AN(p);
- if (best != NULL)
- r = VSA_Build(p, best->ai_addr, best->ai_addrlen);
- else {
+ if (r == NULL) {
r = p;
memcpy(r, d, vsa_suckaddr_len);
}
More information about the varnish-commit
mailing list