From 0506c496286b11ad31bd07b3aacb4b8fe1bff91c Mon Sep 17 00:00:00 2001 From: phk Date: Fri, 20 Jun 2008 14:47:50 +0000 Subject: [PATCH] Add a boolean paramter "log_local_address" which enables logging of the local socket address in the SessionOpen records in SHM. This costs us an extra getsockname(2) call per connection, so default to off. SHM clients can tell the state of this option by the number of fields in SessionOpen: 3 (off) or 4 (on). git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2745 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishd/cache_acceptor.c | 12 ++++++++++-- varnish-cache/bin/varnishd/heritage.h | 3 +++ varnish-cache/bin/varnishd/mgt_param.c | 5 +++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/varnish-cache/bin/varnishd/cache_acceptor.c b/varnish-cache/bin/varnishd/cache_acceptor.c index 27770ea8..60dfb9d2 100644 --- a/varnish-cache/bin/varnishd/cache_acceptor.c +++ b/varnish-cache/bin/varnishd/cache_acceptor.c @@ -119,8 +119,16 @@ VCA_Prep(struct sess *sp) addr, sizeof addr, port, sizeof port); sp->addr = WS_Dup(sp->ws, addr); sp->port = WS_Dup(sp->ws, port); - VSL(SLT_SessionOpen, sp->fd, "%s %s %s", - sp->addr, sp->port, sp->mylsock->name); + if (params->log_local_addr) { + AZ(getsockname(sp->fd, 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", + sp->addr, sp->port, addr, port); + } else { + VSL(SLT_SessionOpen, sp->fd, "%s %s %s", + sp->addr, sp->port, sp->mylsock->name); + } sp->acct.first = sp->t_open; if (need_test) sock_test(sp->fd); diff --git a/varnish-cache/bin/varnishd/heritage.h b/varnish-cache/bin/varnishd/heritage.h index 3e892618..10970a92 100644 --- a/varnish-cache/bin/varnishd/heritage.h +++ b/varnish-cache/bin/varnishd/heritage.h @@ -162,6 +162,9 @@ struct params { /* Log hash string to shm */ unsigned log_hash; + + /* Log local socket address to shm */ + unsigned log_local_addr; }; extern volatile struct params *params; diff --git a/varnish-cache/bin/varnishd/mgt_param.c b/varnish-cache/bin/varnishd/mgt_param.c index cb27e4f4..c3fde983 100644 --- a/varnish-cache/bin/varnishd/mgt_param.c +++ b/varnish-cache/bin/varnishd/mgt_param.c @@ -747,6 +747,11 @@ static const struct parspec parspec[] = { "Log the hash string to shared memory log.\n", 0, "off", "bool" }, + { "log_local_address", tweak_bool, &master.log_local_addr, 0, 0, + "Log the local address on the TCP connection in the " + "SessionOpen shared memory record.\n", + 0, + "off", "bool" }, { "diag_bitmap", tweak_diag_bitmap, 0, 0, 0, "Bitmap controlling diagnostics code:\n" " 0x00000001 - CNT_Session states.\n" -- 2.39.5