[experimental-ims] 8624d49 Move the client IP+port onto the sess structure instead of the sess workspace.
Geoff Simmons
geoff at varnish-cache.org
Tue Jan 10 00:03:28 CET 2012
commit 8624d492a504d40f0794b00a6b036bfd929822d9
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Tue Dec 20 09:01:14 2011 +0000
Move the client IP+port onto the sess structure instead of the
sess workspace.
diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 14b9fe6..d1d67b6 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -600,8 +600,8 @@ struct sess {
struct listen_sock *mylsock;
/* formatted ascii client address */
- char *addr;
- char *port;
+ char addr[ADDR_BUFSIZE];
+ char port[PORT_BUFSIZE];
char *client_identity;
/* HTTP request */
@@ -662,7 +662,7 @@ struct sess {
/* Prototypes etc ----------------------------------------------------*/
/* cache_acceptor.c */
-void VCA_Prep(struct sess *sp);
+void VCA_Prep(const struct sess *sp);
void VCA_Init(void);
void VCA_Shutdown(void);
int VCA_Accept(struct listen_sock *ls, struct wrk_accept *wa);
@@ -997,7 +997,6 @@ void WS_ReleaseP(struct ws *ws, char *ptr);
void WS_Assert(const struct ws *ws);
void WS_Reset(struct ws *ws, char *p);
char *WS_Alloc(struct ws *ws, unsigned bytes);
-char *WS_Dup(struct ws *ws, const char *);
char *WS_Snapshot(struct ws *ws);
unsigned WS_Free(const struct ws *ws);
diff --git a/bin/varnishd/cache/cache_acceptor.c b/bin/varnishd/cache/cache_acceptor.c
index 661b053..6ef9aec 100644
--- a/bin/varnishd/cache/cache_acceptor.c
+++ b/bin/varnishd/cache/cache_acceptor.c
@@ -113,27 +113,9 @@ sock_test(int fd)
*/
void
-VCA_Prep(struct sess *sp)
+VCA_Prep(const struct sess *sp)
{
- char addr[VTCP_ADDRBUFSIZE];
- char port[VTCP_PORTBUFSIZE];
-
- VTCP_name(&sp->sockaddr, sp->sockaddrlen,
- addr, sizeof addr, port, sizeof port);
- sp->addr = WS_Dup(sp->ws, addr);
- sp->port = WS_Dup(sp->ws, port);
- if (cache_param->log_local_addr) {
- AZ(getsockname(sp->fd, (void*)&sp->mysockaddr,
- &sp->mysockaddrlen));
- VTCP_name(&sp->mysockaddr, sp->mysockaddrlen,
- addr, sizeof addr, port, sizeof port);
- WSP(sp, SLT_SessionOpen, "%s %s %s %s",
- sp->addr, sp->port, addr, port);
- } else {
- WSP(sp, SLT_SessionOpen, "%s %s %s",
- sp->addr, sp->port, sp->mylsock->name);
- }
- sp->acct_ses.first = sp->t_open;
+
if (need_test)
sock_test(sp->fd);
if (need_linger)
diff --git a/bin/varnishd/cache/cache_center.c b/bin/varnishd/cache/cache_center.c
index 520c620..a6ea594 100644
--- a/bin/varnishd/cache/cache_center.c
+++ b/bin/varnishd/cache/cache_center.c
@@ -64,6 +64,8 @@ DOT acceptor -> first [style=bold,color=green]
#include "cache.h"
+#include "common/heritage.h"
+
#include "hash/hash_slinger.h"
#include "vcl.h"
#include "vcli_priv.h"
@@ -1005,6 +1007,8 @@ static int
cnt_first(struct sess *sp)
{
struct worker *wrk;
+ char laddr[ADDR_BUFSIZE];
+ char lport[PORT_BUFSIZE];
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
wrk = sp->wrk;
@@ -1020,6 +1024,21 @@ cnt_first(struct sess *sp)
assert(sp->xid == 0);
assert(sp->restarts == 0);
AZ(sp->esi_level);
+ VTCP_name(&sp->sockaddr, sp->sockaddrlen,
+ sp->addr, sizeof sp->addr, sp->port, sizeof sp->port);
+ if (cache_param->log_local_addr) {
+ AZ(getsockname(sp->fd, (void*)&sp->mysockaddr,
+ &sp->mysockaddrlen));
+ VTCP_name(&sp->mysockaddr, sp->mysockaddrlen,
+ laddr, sizeof laddr, lport, sizeof lport);
+ WSP(sp, SLT_SessionOpen, "%s %s %s %s",
+ sp->addr, sp->port, laddr, lport);
+ } else {
+ WSP(sp, SLT_SessionOpen, "%s %s %s",
+ sp->addr, sp->port, sp->mylsock->name);
+ }
+ sp->acct_ses.first = sp->t_open;
+
VCA_Prep(sp);
/* Record the session watermark */
diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c
index 19292ea..65dd5c7 100644
--- a/bin/varnishd/cache/cache_session.c
+++ b/bin/varnishd/cache/cache_session.c
@@ -321,7 +321,6 @@ SES_Delete(struct sess *sp, const char *reason)
{
struct acct *b;
struct sessmem *sm;
- static char noaddr[] = "-";
struct worker *wrk;
struct sesspool *pp;
@@ -340,10 +339,10 @@ SES_Delete(struct sess *sp, const char *reason)
assert(sp->fd < 0);
AZ(sp->vcl);
- if (sp->addr == NULL)
- sp->addr = noaddr;
- if (sp->port == NULL)
- sp->port = noaddr;
+ if (*sp->addr == '\0')
+ strcpy(sp->addr, "-");
+ if (*sp->port == '\0')
+ strcpy(sp->addr, "-");
b = &sp->acct_ses;
assert(!isnan(b->first));
diff --git a/bin/varnishd/cache/cache_ws.c b/bin/varnishd/cache/cache_ws.c
index b5f48d3..be38496 100644
--- a/bin/varnishd/cache/cache_ws.c
+++ b/bin/varnishd/cache/cache_ws.c
@@ -116,22 +116,6 @@ WS_Alloc(struct ws *ws, unsigned bytes)
return (r);
}
-char *
-WS_Dup(struct ws *ws, const char *s)
-{
- unsigned l;
- char *p;
-
- WS_Assert(ws);
- l = strlen(s) + 1;
- p = WS_Alloc(ws, l);
- if (p != NULL)
- memcpy(p, s, l);
- DSL(0x02, SLT_Debug, 0, "WS_Dup(%p, \"%s\") = %p", ws, s, p);
- WS_Assert(ws);
- return (p);
-}
-
unsigned
WS_Free(const struct ws *ws)
{
diff --git a/bin/varnishd/common/common.h b/bin/varnishd/common/common.h
index 3509f25..7fcc7ec 100644
--- a/bin/varnishd/common/common.h
+++ b/bin/varnishd/common/common.h
@@ -60,6 +60,15 @@ struct cli;
*/
#define __state_variable__(xxx) /*lint -esym(838,xxx) */
+/**********************************************************************
+ * NI_MAXHOST and less so NI_MAXSERV, are ridiculously large for numeric
+ * representations of TCP/IP socket addresses, so we use our own.
+ */
+
+#define ADDR_BUFSIZE 64
+#define PORT_BUFSIZE 8
+
+
/**********************************************************************/
/* Name of transient storage */
diff --git a/bin/varnishtest/tests/r00693.vtc b/bin/varnishtest/tests/r00693.vtc
index 37b0a98..ce65be5 100644
--- a/bin/varnishtest/tests/r00693.vtc
+++ b/bin/varnishtest/tests/r00693.vtc
@@ -51,8 +51,8 @@ varnish v1 -arg "-p sess_workspace=1024" -vcl+backend {
"0123456789abcdef" + "0123456789abcdef" +
"0123456789abcdef" + "0123456789abcdef" +
"0123456789abcdef" + "0123456789abcdef" +
- "0123456789abcdef" +
- "0123456";
+ "0123456789abcdef" + "0123456789abcdef" +
+ "0123456789abcde";
set req.http.baz = "BAZ";
return (pass);
}
More information about the varnish-commit
mailing list