r5393 - in trunk/varnish-cache: bin/varnishd include lib/libvarnish lib/libvcl
phk at varnish-cache.org
phk at varnish-cache.org
Mon Oct 4 11:42:11 CEST 2010
Author: phk
Date: 2010-10-04 11:42:11 +0200 (Mon, 04 Oct 2010)
New Revision: 5393
Modified:
trunk/varnish-cache/bin/varnishd/cache.h
trunk/varnish-cache/bin/varnishd/cache_acceptor.c
trunk/varnish-cache/bin/varnishd/cache_backend.c
trunk/varnish-cache/bin/varnishd/cache_backend.h
trunk/varnish-cache/bin/varnishd/cache_backend_cfg.c
trunk/varnish-cache/bin/varnishd/cache_backend_poll.c
trunk/varnish-cache/bin/varnishd/cache_dir_dns.c
trunk/varnish-cache/bin/varnishd/cache_session.c
trunk/varnish-cache/bin/varnishd/cache_vrt_var.c
trunk/varnish-cache/include/libvarnish.h
trunk/varnish-cache/lib/libvarnish/tcp.c
trunk/varnish-cache/lib/libvcl/generate.py
Log:
Switch from struct sockaddr to sockaddr_storage throughout.
Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h 2010-10-04 09:00:53 UTC (rev 5392)
+++ trunk/varnish-cache/bin/varnishd/cache.h 2010-10-04 09:42:11 UTC (rev 5393)
@@ -395,8 +395,8 @@
socklen_t sockaddrlen;
socklen_t mysockaddrlen;
- struct sockaddr *sockaddr;
- struct sockaddr *mysockaddr;
+ struct sockaddr_storage *sockaddr;
+ struct sockaddr_storage *mysockaddr;
struct listen_sock *mylsock;
/* formatted ascii client address */
@@ -468,7 +468,7 @@
struct vdi_simple *vdis;
int fd;
- struct sockaddr *addr;
+ struct sockaddr_storage *addr;
socklen_t addrlen;
uint8_t recycled;
Modified: trunk/varnish-cache/bin/varnishd/cache_acceptor.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_acceptor.c 2010-10-04 09:00:53 UTC (rev 5392)
+++ trunk/varnish-cache/bin/varnishd/cache_acceptor.c 2010-10-04 09:42:11 UTC (rev 5393)
@@ -167,7 +167,7 @@
sp->addr = WS_Dup(sp->ws, addr);
sp->port = WS_Dup(sp->ws, port);
if (params->log_local_addr) {
- AZ(getsockname(sp->fd, sp->mysockaddr, &sp->mysockaddrlen));
+ AZ(getsockname(sp->fd, (void*)sp->mysockaddr, &sp->mysockaddrlen));
TCP_name(sp->mysockaddr, sp->mysockaddrlen,
addr, sizeof addr, port, sizeof port);
VSL(SLT_SessionOpen, sp->fd, "%s %s %s %s",
Modified: trunk/varnish-cache/bin/varnishd/cache_backend.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_backend.c 2010-10-04 09:00:53 UTC (rev 5392)
+++ trunk/varnish-cache/bin/varnishd/cache_backend.c 2010-10-04 09:42:11 UTC (rev 5393)
@@ -129,7 +129,7 @@
*/
static int
-vbe_TryConnect(const struct sess *sp, int pf, const struct sockaddr *sa,
+vbe_TryConnect(const struct sess *sp, int pf, const struct sockaddr_storage *sa,
socklen_t salen, const struct vdi_simple *vs)
{
int s, i, tmo;
@@ -148,10 +148,7 @@
tmo = (int)(tmod * 1000.0);
- if (tmo > 0)
- i = TCP_connect(s, sa, salen, tmo);
- else
- i = connect(s, sa, salen);
+ i = TCP_connect(s, sa, salen, tmo);
if (i != 0) {
AZ(close(s));
Modified: trunk/varnish-cache/bin/varnishd/cache_backend.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_backend.h 2010-10-04 09:00:53 UTC (rev 5392)
+++ trunk/varnish-cache/bin/varnishd/cache_backend.h 2010-10-04 09:42:11 UTC (rev 5393)
@@ -122,9 +122,9 @@
char *ipv6_addr;
char *port;
- struct sockaddr *ipv4;
+ struct sockaddr_storage *ipv4;
socklen_t ipv4len;
- struct sockaddr *ipv6;
+ struct sockaddr_storage *ipv6;
socklen_t ipv6len;
unsigned n_conn;
Modified: trunk/varnish-cache/bin/varnishd/cache_backend_cfg.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_backend_cfg.c 2010-10-04 09:00:53 UTC (rev 5392)
+++ trunk/varnish-cache/bin/varnishd/cache_backend_cfg.c 2010-10-04 09:42:11 UTC (rev 5393)
@@ -151,11 +151,12 @@
*/
static void
-copy_sockaddr(struct sockaddr **sa, socklen_t *len, const unsigned char *src)
+copy_sockaddr(struct sockaddr_storage **sa, socklen_t *len,
+ const unsigned char *src)
{
assert(*src > 0);
- *sa = malloc(*src);
+ *sa = malloc(*src); /* XXX: malloc(sizeof **sa) ? */
XXXAN(*sa);
memcpy(*sa, src + 1, *src);
*len = *src;
Modified: trunk/varnish-cache/bin/varnishd/cache_backend_poll.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_backend_poll.c 2010-10-04 09:00:53 UTC (rev 5392)
+++ trunk/varnish-cache/bin/varnishd/cache_backend_poll.c 2010-10-04 09:42:11 UTC (rev 5393)
@@ -109,7 +109,7 @@
*/
static int
-vbp_connect(int pf, const struct sockaddr *sa, socklen_t salen, int tmo)
+vbp_connect(int pf, const struct sockaddr_storage *sa, socklen_t salen, int tmo)
{
int s, i;
Modified: trunk/varnish-cache/bin/varnishd/cache_dir_dns.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_dir_dns.c 2010-10-04 09:00:53 UTC (rev 5392)
+++ trunk/varnish-cache/bin/varnishd/cache_dir_dns.c 2010-10-04 09:42:11 UTC (rev 5393)
@@ -128,17 +128,17 @@
/* Check if a backends socket is the same as addr */
static int
vdi_dns_comp_addrinfo(const struct director *dir,
- struct sockaddr *addr,
+ struct sockaddr_storage *addr,
const socklen_t len)
{
struct backend *bp;
bp = vdi_get_backend_if_simple(dir);
AN(bp);
- if (addr->sa_family == PF_INET && bp->ipv4) {
+ if (addr->ss_family == PF_INET && bp->ipv4) {
return (vdi_dns_comp_addrinfo4(bp, (struct sockaddr_in *)
addr, len));
- } else if (addr->sa_family == PF_INET6 && bp->ipv6) {
+ } else if (addr->ss_family == PF_INET6 && bp->ipv6) {
return (vdi_dns_comp_addrinfo6(bp, (struct sockaddr_in6 *)
addr, len));
}
@@ -298,8 +298,10 @@
continue;
for (i = 0; i < vs->nhosts; i++) {
+ struct sockaddr_storage ss_hack;
+ memcpy(&ss_hack, res->ai_addr, res->ai_addrlen);
if (vdi_dns_comp_addrinfo(vs->hosts[i],
- res->ai_addr, res->ai_addrlen)) {
+ &ss_hack, res->ai_addrlen)) {
new->hosts[host] = vs->hosts[i];
CHECK_OBJ_NOTNULL(new->hosts[host],
DIRECTOR_MAGIC);
Modified: trunk/varnish-cache/bin/varnishd/cache_session.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_session.c 2010-10-04 09:00:53 UTC (rev 5392)
+++ trunk/varnish-cache/bin/varnishd/cache_session.c 2010-10-04 09:42:11 UTC (rev 5393)
@@ -169,7 +169,7 @@
sp->sockaddrlen = sizeof(sm->sockaddr[0]);
sp->mysockaddr = (void*)(&sm->sockaddr[1]);
sp->mysockaddrlen = sizeof(sm->sockaddr[1]);
- sp->sockaddr->sa_family = sp->mysockaddr->sa_family = PF_UNSPEC;
+ sp->sockaddr->ss_family = sp->mysockaddr->ss_family = PF_UNSPEC;
sp->t_open = NAN;
sp->t_req = NAN;
sp->t_resp = NAN;
Modified: trunk/varnish-cache/bin/varnishd/cache_vrt_var.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_vrt_var.c 2010-10-04 09:00:53 UTC (rev 5392)
+++ trunk/varnish-cache/bin/varnishd/cache_vrt_var.c 2010-10-04 09:42:11 UTC (rev 5393)
@@ -291,7 +291,7 @@
return(sp->vbc->backend->vcl_name);
}
-struct sockaddr *
+struct sockaddr_storage *
VRT_r_beresp_backend_ip(const struct sess *sp)
{
@@ -480,20 +480,20 @@
/*--------------------------------------------------------------------*/
-struct sockaddr *
+struct sockaddr_storage *
VRT_r_client_ip(const struct sess *sp)
{
return (sp->sockaddr);
}
-struct sockaddr *
+struct sockaddr_storage *
VRT_r_server_ip(struct sess *sp)
{
int i;
- if (sp->mysockaddr->sa_family == AF_UNSPEC) {
- i = getsockname(sp->fd, sp->mysockaddr, &sp->mysockaddrlen);
+ if (sp->mysockaddr->ss_family == AF_UNSPEC) {
+ i = getsockname(sp->fd, (void*)sp->mysockaddr, &sp->mysockaddrlen);
assert(TCP_Check(i));
}
@@ -531,8 +531,8 @@
VRT_r_server_port(struct sess *sp)
{
- if (sp->mysockaddr->sa_family == AF_UNSPEC)
- AZ(getsockname(sp->fd, sp->mysockaddr, &sp->mysockaddrlen));
+ if (sp->mysockaddr->ss_family == AF_UNSPEC)
+ AZ(getsockname(sp->fd, (void*)sp->mysockaddr, &sp->mysockaddrlen));
return (TCP_port(sp->mysockaddr));
}
Modified: trunk/varnish-cache/include/libvarnish.h
===================================================================
--- trunk/varnish-cache/include/libvarnish.h 2010-10-04 09:00:53 UTC (rev 5392)
+++ trunk/varnish-cache/include/libvarnish.h 2010-10-04 09:42:11 UTC (rev 5393)
@@ -76,10 +76,10 @@
int TCP_nonblocking(int sock);
int TCP_linger(int sock, int linger);
#ifdef SOL_SOCKET
-int TCP_port(const struct sockaddr *addr);
-void TCP_name(const struct sockaddr *addr, unsigned l, char *abuf,
+int TCP_port(const struct sockaddr_storage *addr);
+void TCP_name(const struct sockaddr_storage *addr, unsigned l, char *abuf,
unsigned alen, char *pbuf, unsigned plen);
-int TCP_connect(int s, const struct sockaddr *name, socklen_t namelen,
+int TCP_connect(int s, const struct sockaddr_storage *name, socklen_t namelen,
int msec);
void TCP_close(int *s);
void TCP_set_read_timeout(int s, double seconds);
Modified: trunk/varnish-cache/lib/libvarnish/tcp.c
===================================================================
--- trunk/varnish-cache/lib/libvarnish/tcp.c 2010-10-04 09:00:53 UTC (rev 5392)
+++ trunk/varnish-cache/lib/libvarnish/tcp.c 2010-10-04 09:42:11 UTC (rev 5393)
@@ -64,14 +64,14 @@
/*--------------------------------------------------------------------*/
int
-TCP_port(const struct sockaddr *addr)
+TCP_port(const struct sockaddr_storage *addr)
{
- if (addr->sa_family == AF_INET) {
+ if (addr->ss_family == AF_INET) {
const struct sockaddr_in *ain = (const void *)addr;
return ntohs((ain->sin_port));
}
- if (addr->sa_family == AF_INET6) {
+ if (addr->ss_family == AF_INET6) {
const struct sockaddr_in6 *ain = (const void *)addr;
return ntohs((ain->sin6_port));
}
@@ -82,12 +82,12 @@
/*--------------------------------------------------------------------*/
void
-TCP_name(const struct sockaddr *addr, unsigned l, char *abuf, unsigned alen,
- char *pbuf, unsigned plen)
+TCP_name(const struct sockaddr_storage *addr, unsigned l,
+ char *abuf, unsigned alen, char *pbuf, unsigned plen)
{
int i;
- i = getnameinfo(addr, l, abuf, alen, pbuf, plen,
+ i = getnameinfo((const void *)addr, l, abuf, alen, pbuf, plen,
NI_NUMERICHOST | NI_NUMERICSERV);
if (i) {
/*
@@ -113,12 +113,11 @@
TCP_myname(int sock, char *abuf, unsigned alen, char *pbuf, unsigned plen)
{
struct sockaddr_storage addr_s;
- struct sockaddr *addr = (void*)&addr_s;
socklen_t l;
l = sizeof addr_s;
- AZ(getsockname(sock, addr, &l));
- TCP_name(addr, l, abuf, alen, pbuf, plen);
+ AZ(getsockname(sock, (void *)&addr_s, &l));
+ TCP_name(&addr_s, l, abuf, alen, pbuf, plen);
}
/*--------------------------------------------------------------------*/
@@ -126,12 +125,11 @@
TCP_hisname(int sock, char *abuf, unsigned alen, char *pbuf, unsigned plen)
{
struct sockaddr_storage addr_s;
- struct sockaddr *addr = (void*)&addr_s;
socklen_t l;
l = sizeof addr_s;
- if (!getpeername(sock, addr, &l))
- TCP_name(addr, l, abuf, alen, pbuf, plen);
+ if (!getpeername(sock, (void*)&addr_s, &l))
+ TCP_name(&addr_s, l, abuf, alen, pbuf, plen);
else {
strlcpy(abuf, "<none>", alen);
strlcpy(pbuf, "<none>", plen);
@@ -209,7 +207,7 @@
*/
int
-TCP_connect(int s, const struct sockaddr *name, socklen_t namelen, int msec)
+TCP_connect(int s, const struct sockaddr_storage *name, socklen_t namelen, int msec)
{
int i, k;
socklen_t l;
@@ -218,13 +216,15 @@
assert(s >= 0);
/* Set the socket non-blocking */
- (void)TCP_nonblocking(s);
+ if (msec > 0)
+ (void)TCP_nonblocking(s);
/* Attempt the connect */
- i = connect(s, name, namelen);
+ i = connect(s, (const void *)name, namelen);
if (i == 0 || errno != EINPROGRESS)
return (i);
+ assert(msec > 0);
/* Exercise our patience, polling for write */
fds[0].fd = s;
fds[0].events = POLLWRNORM;
Modified: trunk/varnish-cache/lib/libvcl/generate.py
===================================================================
--- trunk/varnish-cache/lib/libvcl/generate.py 2010-10-04 09:00:53 UTC (rev 5392)
+++ trunk/varnish-cache/lib/libvcl/generate.py 2010-10-04 09:42:11 UTC (rev 5393)
@@ -405,7 +405,7 @@
# VCL to C type conversion
vcltypes = {
- 'IP': "struct sockaddr *",
+ 'IP': "struct sockaddr_storage *",
'STRING': "const char *",
'BOOL': "unsigned",
'BACKEND': "struct director *",
More information about the varnish-commit
mailing list