[master] af9b7f66a Polish VTCP usage in the acceptor setup

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Mon Dec 30 11:49:06 UTC 2019


commit af9b7f66a8902e99ca9b5fbdac70cf06495b81f8
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Mon Dec 30 12:37:12 2019 +0100

    Polish VTCP usage in the acceptor setup
    
    This adds the errno value to error logs for TCP fast open and accept
    filters. For FreeBSD errno is cleared prior to calling setsockopt with
    the hope that it will help understand if it's actually failing with an
    undocumented ENOENT.
    
    Speaking of documentation, the return value is either 0 or -1 for so
    there's no point in logging that.

diff --git a/bin/varnishd/cache/cache_acceptor.c b/bin/varnishd/cache/cache_acceptor.c
index d230b43f3..36eddcca7 100644
--- a/bin/varnishd/cache/cache_acceptor.c
+++ b/bin/varnishd/cache/cache_acceptor.c
@@ -623,14 +623,11 @@ ccf_start(struct cli *cli, const char * const *av, void *priv)
 	VTAILQ_FOREACH(ls, &heritage.socks, list) {
 		CHECK_OBJ_NOTNULL(ls->transport, TRANSPORT_MAGIC);
 		assert (ls->sock > 0);	// We know where stdin is
-		if (cache_param->tcp_fastopen) {
-			int i;
-			i = VTCP_fastopen(ls->sock, cache_param->listen_depth);
-			if (i)
-				VSL(SLT_Error, 0,
-				    "Kernel TCP Fast Open: sock=%d, ret=%d %s",
-				    ls->sock, i, vstrerror(errno));
-		}
+		if (cache_param->tcp_fastopen &&
+		    VTCP_fastopen(ls->sock, cache_param->listen_depth))
+			VSL(SLT_Error, 0,
+			    "Kernel TCP Fast Open: sock=%d, errno=%d %s",
+			    ls->sock, errno, vstrerror(errno));
 		if (listen(ls->sock, cache_param->listen_depth)) {
 			VCLI_SetResult(cli, CLIS_CANT);
 			VCLI_Out(cli, "Listen failed on socket '%s': %s",
@@ -638,14 +635,10 @@ ccf_start(struct cli *cli, const char * const *av, void *priv)
 			return;
 		}
 		vca_tcp_opt_set(ls->sock, ls->uds, 1);
-		if (cache_param->accept_filter) {
-			int i;
-			i = VTCP_filter_http(ls->sock);
-			if (i)
-				VSL(SLT_Error, 0,
-				    "Kernel filtering: sock=%d, ret=%d %s",
-				    ls->sock, i, vstrerror(errno));
-		}
+		if (cache_param->accept_filter && VTCP_filter_http(ls->sock))
+			VSL(SLT_Error, 0,
+			    "Kernel filtering: sock=%d, errno=%d %s",
+			    ls->sock, errno, vstrerror(errno));
 	}
 
 	need_test = 1;
diff --git a/lib/libvarnish/vtcp.c b/lib/libvarnish/vtcp.c
index 625438ab1..1d7ca9a18 100644
--- a/lib/libvarnish/vtcp.c
+++ b/lib/libvarnish/vtcp.c
@@ -151,10 +151,11 @@ VTCP_filter_http(int sock)
 	int retval;
 	struct accept_filter_arg afa;
 
-	memset(&afa, 0, sizeof(afa));
-	strcpy(afa.af_name, "httpready");
+	memset(&afa, 0, sizeof afa);
+	bprintf(afa.af_name, "httpready");
+	errno = 0;
 	retval = setsockopt(sock, SOL_SOCKET, SO_ACCEPTFILTER,
-	    &afa, sizeof afa );
+	    &afa, sizeof afa);
 	return (retval);
 }
 
@@ -166,7 +167,7 @@ VTCP_filter_http(int sock)
 	int retval;
 	int defer = 1;
 
-	retval = setsockopt(sock, SOL_TCP,TCP_DEFER_ACCEPT,
+	retval = setsockopt(sock, SOL_TCP, TCP_DEFER_ACCEPT,
 	    &defer, sizeof defer);
 	return (retval);
 }


More information about the varnish-commit mailing list