r66 - in trunk/varnish-cache: bin/varnishd include

phk at projects.linpro.no phk at projects.linpro.no
Fri Mar 24 10:45:39 CET 2006


Author: phk
Date: 2006-03-24 10:45:39 +0100 (Fri, 24 Mar 2006)
New Revision: 66

Modified:
   trunk/varnish-cache/bin/varnishd/cache.h
   trunk/varnish-cache/bin/varnishd/cache_acceptor.c
   trunk/varnish-cache/include/shmlog_tags.h
Log:
Log remote IP#:port on session open


Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h	2006-03-24 09:14:06 UTC (rev 65)
+++ trunk/varnish-cache/bin/varnishd/cache.h	2006-03-24 09:45:39 UTC (rev 66)
@@ -3,9 +3,11 @@
  */
 
 #define VCA_RXBUFSIZE		1024
+#define VCA_ADDRBUFSIZE		32
 struct sess {
 	int		fd;
 	char		rcv[VCA_RXBUFSIZE + 1];
+	char		addr[VCA_ADDRBUFSIZE];
 	unsigned	rcv_len;
 	struct event	rd_e;
 };

Modified: trunk/varnish-cache/bin/varnishd/cache_acceptor.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_acceptor.c	2006-03-24 09:14:06 UTC (rev 65)
+++ trunk/varnish-cache/bin/varnishd/cache_acceptor.c	2006-03-24 09:45:39 UTC (rev 66)
@@ -11,10 +11,14 @@
 #include <sys/types.h>
 #include <sys/socket.h>
 
+#include <netdb.h>
+
 #include <sbuf.h>
 #include <event.h>
 
+#include "libvarnish.h"
 #include "heritage.h"
+#include "shmlog.h"
 #include "cache.h"
 
 static struct event_base *evb;
@@ -31,7 +35,14 @@
 	printf("%s(%d, %d, ...)\n", __func__, fd, event);
 	assert(VCA_RXBUFSIZE - sp->rcv_len > 0);
 	i = read(fd, sp->rcv + sp->rcv_len, VCA_RXBUFSIZE - sp->rcv_len);
-	assert(i > 0);
+	if (i <= 0) {
+		VSL(SLT_SessionClose, sp->fd, "remote %d", sp->rcv_len);
+		event_del(&sp->rd_e);
+		close(sp->fd);
+		free(sp);
+		return;
+	}
+
 	sp->rcv_len += i;
 	sp->rcv[sp->rcv_len] = '\0';
 
@@ -58,19 +69,26 @@
 	socklen_t l;
 	struct sockaddr addr;
 	struct sess *sp;
+	char port[10];
 
 	sp = calloc(sizeof *sp, 1);
-	assert(sp != NULL);
+	assert(sp != NULL);	/*
+				 * XXX: this is probably one we should handle
+				 * XXX: accept, emit error NNN and close
+				 */
 
-	printf("%s(%d, %d, ...)\n", __func__, fd, event);
-
 	l = sizeof addr;
 	sp->fd = accept(fd, &addr, &l);
 	if (sp->fd < 0) {
 		free(sp);
 		return;
 	}
-
+	AZ(getnameinfo(&addr, l,
+	    sp->addr, VCA_ADDRBUFSIZE,
+	    port, sizeof port, NI_NUMERICHOST | NI_NUMERICSERV));
+	strlcat(sp->addr, ":", VCA_ADDRBUFSIZE);
+	strlcat(sp->addr, port, VCA_ADDRBUFSIZE);
+	VSL(SLT_SessionOpen, sp->fd, "%s", sp->addr);
 	event_set(&sp->rd_e, sp->fd, EV_READ | EV_PERSIST,
 	    http_read_f, sp);
 	event_base_set(evb, &sp->rd_e);

Modified: trunk/varnish-cache/include/shmlog_tags.h
===================================================================
--- trunk/varnish-cache/include/shmlog_tags.h	2006-03-24 09:14:06 UTC (rev 65)
+++ trunk/varnish-cache/include/shmlog_tags.h	2006-03-24 09:45:39 UTC (rev 66)
@@ -7,7 +7,8 @@
  */
 
 SLTM(CLI)
-SLTM(SessionId)
+SLTM(SessionOpen)
+SLTM(SessionClose)
 SLTM(ClientAddr)
 SLTM(Request)
 SLTM(URL)




More information about the varnish-commit mailing list