Commit 9ecc0302 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Rework the way we do ascii representations of addresses


git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@468 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent d558d26e
......@@ -159,7 +159,7 @@ struct objhead {
struct client {
TAILQ_ENTRY(client) list;
unsigned nsess;
char addr[TCP_ADDRBUFFSIZE];
char addr[TCP_ADDRBUFSIZE];
uint64_t bytes;
};
......@@ -170,7 +170,8 @@ struct sess {
struct worker *wrk;
/* formatted ascii client address */
char addr[TCP_ADDRBUFFSIZE];
char addr[TCP_ADDRBUFSIZE];
char port[TCP_PORTBUFSIZE];
struct client *client;
/* HTTP request */
......
......@@ -7,6 +7,7 @@
*/
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
......@@ -184,6 +185,8 @@ accept_f(int fd, short event, void *arg)
l = sizeof addr;
i = accept(fd, addr, &l);
if (i < 0) {
VSL(SLT_Debug, fd, "Accept failed errno=%d", errno);
/* XXX: stats ? */
return;
}
sp = SES_New(addr, l);
......@@ -201,8 +204,8 @@ accept_f(int fd, short event, void *arg)
AZ(setsockopt(sp->fd, SOL_SOCKET, SO_LINGER, &linger, sizeof linger));
#endif
TCP_name(addr, l, sp->addr);
VSL(SLT_SessionOpen, sp->fd, "%s", sp->addr);
TCP_name(addr, l, sp->addr, sizeof sp->addr, sp->port, sizeof sp->port);
VSL(SLT_SessionOpen, sp->fd, "%s %s", sp->addr, sp->port);
(void)time(&sp->t_resp);
TAILQ_INSERT_TAIL(&sesshead, sp, list);
http_RecvHead(sp->http, sp->fd, evb, vca_callback, sp);
......@@ -272,7 +275,7 @@ vca_return_session(struct sess *sp)
{
if (sp->fd >= 0) {
VSL(SLT_SessionReuse, sp->fd, "%s", sp->addr);
VSL(SLT_SessionReuse, sp->fd, "%s %s", sp->addr, sp->port);
assert(sizeof sp == write(pipes[1], &sp, sizeof sp));
} else {
SES_Delete(sp);
......
......@@ -186,7 +186,8 @@ static int
vbe_connect(struct backend *bp)
{
int s;
char buf[TCP_ADDRBUFFSIZE * 2 + 1], *p;
char abuf1[TCP_ADDRBUFSIZE], abuf2[TCP_ADDRBUFSIZE];
char pbuf1[TCP_PORTBUFSIZE], pbuf2[TCP_PORTBUFSIZE];
struct addrinfo *ai;
assert(bp != NULL);
......@@ -196,11 +197,10 @@ vbe_connect(struct backend *bp)
if (s < 0)
return (s);
TCP_myname(s, buf);
p = strchr(buf, '\0');
*p++ = ' ';
TCP_name(ai->ai_addr, ai->ai_addrlen, p);
VSL(SLT_BackendOpen, s, buf);
TCP_myname(s, abuf1, sizeof abuf1, pbuf1, sizeof pbuf1);
TCP_name(ai->ai_addr, ai->ai_addrlen,
abuf2, sizeof abuf2, pbuf2, sizeof pbuf2);
VSL(SLT_BackendOpen, s, "%s %s %s %s", abuf1, pbuf1, abuf2, pbuf2);
return (s);
}
......
......@@ -9,9 +9,9 @@ void VSL_MgtInit(const char *fn, unsigned size);
extern struct varnish_stats *VSL_stats;
/* tcp.c */
#define TCP_ADDRBUFFSIZE 64 /* Sizeof ascii representation */
void TCP_name(struct sockaddr *addr, unsigned l, char *buf);
void TCP_myname(int sock, char *buf);
/* NI_MAXHOST and NI_MAXSERV are ridiculously long for numeric format */
#define TCP_ADDRBUFSIZE 64
#define TCP_PORTBUFSIZE 16
void TCP_name(struct sockaddr *addr, unsigned l, char *abuf, unsigned alen, char *pbuf, unsigned plen);
void TCP_myname(int sock, char *abuf, unsigned alen, char *pbuf, unsigned plen);
......@@ -17,33 +17,31 @@
/*--------------------------------------------------------------------*/
void
TCP_name(struct sockaddr *addr, unsigned l, char *buf)
TCP_name(struct sockaddr *addr, unsigned l, char *abuf, unsigned alen, char *pbuf, unsigned plen)
{
int i;
char port[NI_MAXSERV];
i = getnameinfo(addr, l, buf, TCP_ADDRBUFFSIZE,
port, sizeof port, NI_NUMERICHOST | NI_NUMERICSERV);
i = getnameinfo(addr, l, abuf, alen, pbuf, plen,
NI_NUMERICHOST | NI_NUMERICSERV);
if (i) {
printf("getnameinfo = %d %s\n", i, gai_strerror(i));
strcpy(buf, "Conversion:Failed");
strlcpy(abuf, "Conversion", alen);
strlcpy(pbuf, "Failed", plen);
return;
}
strlcat(buf, " ", TCP_ADDRBUFFSIZE);
strlcat(buf, port, TCP_ADDRBUFFSIZE);
}
/*--------------------------------------------------------------------*/
void
TCP_myname(int sock, char *buf)
TCP_myname(int sock, char *abuf, unsigned alen, char *pbuf, unsigned plen)
{
struct sockaddr addr[2]; /* XXX: IPv6 hack */
socklen_t l;
l = sizeof addr;
AZ(getsockname(sock, addr, &l));
TCP_name(addr, l, buf);
TCP_name(addr, l, abuf, alen, pbuf, plen);
}
/*--------------------------------------------------------------------*/
......
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