[master] 3eb59f1 Add PFD_LocalName() and PFD_RemoteName() to the FD pool interface.

Geoff Simmons geoff at uplex.de
Mon Mar 12 09:45:10 UTC 2018


commit 3eb59f10b7d3380c65c7d215e6b11c8b059d98eb
Author: Geoff Simmons <geoff at uplex.de>
Date:   Thu Mar 8 16:18:12 2018 +0100

    Add PFD_LocalName() and PFD_RemoteName() to the FD pool interface.
    
    This makes logging the local and peer address in BackendOpen
    independent of the socket type.

diff --git a/bin/varnishd/cache/cache_backend.c b/bin/varnishd/cache/cache_backend.c
index 9c0231b..11a35c9 100644
--- a/bin/varnishd/cache/cache_backend.c
+++ b/bin/varnishd/cache/cache_backend.c
@@ -136,8 +136,8 @@ vbe_dir_getfd(struct worker *wrk, struct backend *bp, struct busyobj *bo,
 	if (bp->proxy_header != 0)
 		VPX_Send_Proxy(*fdp, bp->proxy_header, bo->sp);
 
-	VTCP_myname(*fdp, abuf1, sizeof abuf1, pbuf1, sizeof pbuf1);
-	VTCP_hisname(*fdp, abuf2, sizeof abuf2, pbuf2, sizeof pbuf2);
+	PFD_LocalName(pfd, abuf1, sizeof abuf1, pbuf1, sizeof pbuf1);
+	PFD_RemoteName(pfd, abuf2, sizeof abuf2, pbuf2, sizeof pbuf2);
 	VSLb(bo->vsl, SLT_BackendOpen, "%d %s %s %s %s %s",
 	    *fdp, bp->director->display_name, abuf2, pbuf2, abuf1, pbuf1);
 
diff --git a/bin/varnishd/cache/cache_tcp_pool.c b/bin/varnishd/cache/cache_tcp_pool.c
index 73b7f4f..c63ad64 100644
--- a/bin/varnishd/cache/cache_tcp_pool.c
+++ b/bin/varnishd/cache/cache_tcp_pool.c
@@ -62,31 +62,20 @@ struct pfd {
 	pthread_cond_t		*cond;
 };
 
-unsigned
-PFD_State(const struct pfd *p)
-{
-	CHECK_OBJ_NOTNULL(p, PFD_MAGIC);
-	return (p->state);
-}
-
-int *
-PFD_Fd(struct pfd *p)
-{
-	CHECK_OBJ_NOTNULL(p, PFD_MAGIC);
-	return (&(p->fd));
-}
-
 /*--------------------------------------------------------------------
  */
 
 typedef int cp_open_f(const struct conn_pool *, double tmo, const void **privp);
 typedef void cp_close_f(struct pfd *);
 typedef int cp_cmp_f(const struct conn_pool *, const void *priv);
+typedef void cp_name_f(const struct pfd *, char *, unsigned, char *, unsigned);
 
 struct cp_methods {
 	cp_open_f				*open;
 	cp_close_f				*close;
 	cp_cmp_f				*cmp;
+	cp_name_f				*local_name;
+	cp_name_f				*remote_name;
 };
 
 struct conn_pool {
@@ -125,6 +114,41 @@ static VTAILQ_HEAD(, conn_pool)	conn_pools =
     VTAILQ_HEAD_INITIALIZER(conn_pools);
 
 /*--------------------------------------------------------------------
+ */
+
+unsigned
+PFD_State(const struct pfd *p)
+{
+	CHECK_OBJ_NOTNULL(p, PFD_MAGIC);
+	return (p->state);
+}
+
+int *
+PFD_Fd(struct pfd *p)
+{
+	CHECK_OBJ_NOTNULL(p, PFD_MAGIC);
+	return (&(p->fd));
+}
+
+void
+PFD_LocalName(const struct pfd *p, char *abuf, unsigned alen, char *pbuf,
+	      unsigned plen)
+{
+	CHECK_OBJ_NOTNULL(p, PFD_MAGIC);
+	CHECK_OBJ_NOTNULL(p->conn_pool, CONN_POOL_MAGIC);
+	p->conn_pool->methods->local_name(p, abuf, alen, pbuf, plen);
+}
+
+void
+PFD_RemoteName(const struct pfd *p, char *abuf, unsigned alen, char *pbuf,
+	       unsigned plen)
+{
+	CHECK_OBJ_NOTNULL(p, PFD_MAGIC);
+	CHECK_OBJ_NOTNULL(p->conn_pool, CONN_POOL_MAGIC);
+	p->conn_pool->methods->remote_name(p, abuf, alen, pbuf, plen);
+}
+
+/*--------------------------------------------------------------------
  * Waiter-handler
  */
 
@@ -533,10 +557,28 @@ vtp_cmp(const struct conn_pool *cp, const void *priv)
 	return (0);
 }
 
+static void v_matchproto_(cp_name_f)
+vtp_local_name(const struct pfd *pfd, char *addr, unsigned alen, char *pbuf,
+	       unsigned plen)
+{
+	CHECK_OBJ_NOTNULL(pfd, PFD_MAGIC);
+	VTCP_myname(pfd->fd, addr, alen, pbuf, plen);
+}
+
+static void v_matchproto_(cp_name_f)
+vtp_remote_name(const struct pfd *pfd, char *addr, unsigned alen, char *pbuf,
+		unsigned plen)
+{
+	CHECK_OBJ_NOTNULL(pfd, PFD_MAGIC);
+	VTCP_hisname(pfd->fd, addr, alen, pbuf, plen);
+}
+
 static const struct cp_methods vtp_methods = {
 	.open = vtp_open,
 	.close = vtp_close,
 	.cmp = vtp_cmp,
+	.local_name = vtp_local_name,
+	.remote_name = vtp_remote_name,
 };
 
 
diff --git a/bin/varnishd/cache/cache_tcp_pool.h b/bin/varnishd/cache/cache_tcp_pool.h
index f5e25c5..6c792c1 100644
--- a/bin/varnishd/cache/cache_tcp_pool.h
+++ b/bin/varnishd/cache/cache_tcp_pool.h
@@ -42,6 +42,8 @@ struct pfd;
 
 unsigned PFD_State(const struct pfd *);
 int *PFD_Fd(struct pfd *);
+void PFD_LocalName(const struct pfd *, char *, unsigned, char *, unsigned);
+void PFD_RemoteName(const struct pfd *, char *, unsigned, char *, unsigned);
 
 /*---------------------------------------------------------------------
 


More information about the varnish-commit mailing list