[6.0] a475d980e build: Simply require that SO_???TIMEO are present

Martin Blix Grydeland martin at varnish-software.com
Fri Nov 19 14:58:10 UTC 2021


commit a475d980e0d970471623c8c6b1a539ce6555d569
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Wed Sep 22 19:46:18 2021 +0200

    build: Simply require that SO_???TIMEO are present
    
    Closes #3692

diff --git a/bin/varnishd/cache/cache_acceptor.c b/bin/varnishd/cache/cache_acceptor.c
index 035540ff6..68bc2047e 100644
--- a/bin/varnishd/cache/cache_acceptor.c
+++ b/bin/varnishd/cache/cache_acceptor.c
@@ -95,14 +95,8 @@ static struct tcp_opt {
 	TCPO(SOL_SOCKET, SO_LINGER, struct linger, 0)
 	TCPO(SOL_SOCKET, SO_KEEPALIVE, int, 0)
 	TCPO(IPPROTO_TCP, TCP_NODELAY, int, 1)
-
-#ifdef SO_SNDTIMEO_WORKS
 	TCPO(SOL_SOCKET, SO_SNDTIMEO, struct timeval, 0)
-#endif
-
-#ifdef SO_RCVTIMEO_WORKS
 	TCPO(SOL_SOCKET, SO_RCVTIMEO, struct timeval, 0)
-#endif
 
 #ifdef HAVE_TCP_KEEP
 	TCPO(IPPROTO_TCP, TCP_KEEPIDLE, int, 1)
@@ -194,16 +188,12 @@ vca_tcp_opt_init(void)
 		}						\
 	} while (0)
 
-#ifdef SO_SNDTIMEO_WORKS
 		} else if (!strcmp(to->strname, "SO_SNDTIMEO")) {
 			tv = VTIM_timeval(cache_param->idle_send_timeout);
 			NEW_VAL(to, tv);
-#endif
-#ifdef SO_RCVTIMEO_WORKS
 		} else if (!strcmp(to->strname, "SO_RCVTIMEO")) {
 			tv = VTIM_timeval(cache_param->timeout_idle);
 			NEW_VAL(to, tv);
-#endif
 #ifdef HAVE_TCP_KEEP
 		} else if (!strcmp(to->strname, "TCP_KEEPIDLE")) {
 			x = (int)(cache_param->tcp_keepalive_time);
diff --git a/bin/varnishtest/tests/b00020.vtc b/bin/varnishtest/tests/b00020.vtc
index 1f0427c11..fc7c7c2d8 100644
--- a/bin/varnishtest/tests/b00020.vtc
+++ b/bin/varnishtest/tests/b00020.vtc
@@ -1,7 +1,5 @@
 varnishtest "Check that between_bytes_timeout behaves from parameters"
 
-feature SO_RCVTIMEO_WORKS
-
 server s1 {
 	rxreq
 	send "HTTP/1.0 200 OK\r\nConnection: close\r\n\r\n"
diff --git a/bin/varnishtest/tests/b00021.vtc b/bin/varnishtest/tests/b00021.vtc
index 46be8cb4f..f0c4c0ce2 100644
--- a/bin/varnishtest/tests/b00021.vtc
+++ b/bin/varnishtest/tests/b00021.vtc
@@ -1,7 +1,5 @@
 varnishtest "Check the between_bytes_timeout behaves from vcl"
 
-feature SO_RCVTIMEO_WORKS
-
 server s1 {
 	rxreq
 	send "HTTP/1.0 200 OK\r\nConnection: close\r\n\r\n"
diff --git a/bin/varnishtest/tests/b00022.vtc b/bin/varnishtest/tests/b00022.vtc
index 7bf6d9575..fee5db3d9 100644
--- a/bin/varnishtest/tests/b00022.vtc
+++ b/bin/varnishtest/tests/b00022.vtc
@@ -1,7 +1,5 @@
 varnishtest "Check the between_bytes_timeout behaves from backend definition"
 
-feature SO_RCVTIMEO_WORKS
-
 server s1 {
 	rxreq
 	send "HTTP/1.0 200 OK\r\nConnection: close\r\n\r\n"
diff --git a/bin/varnishtest/tests/b00023.vtc b/bin/varnishtest/tests/b00023.vtc
index 9ee5ed340..e2b7a3602 100644
--- a/bin/varnishtest/tests/b00023.vtc
+++ b/bin/varnishtest/tests/b00023.vtc
@@ -1,7 +1,5 @@
 varnishtest "Check that the first_byte_timeout works"
 
-feature SO_RCVTIMEO_WORKS
-
 # From VCL
 
 server s1 {
diff --git a/bin/varnishtest/tests/b00026.vtc b/bin/varnishtest/tests/b00026.vtc
index 48fce004b..e12676985 100644
--- a/bin/varnishtest/tests/b00026.vtc
+++ b/bin/varnishtest/tests/b00026.vtc
@@ -1,7 +1,5 @@
 varnishtest "Check the precedence for timeouts"
 
-feature SO_RCVTIMEO_WORKS
-
 server s1 {
 	rxreq
 	expect req.url == "from_backend"
diff --git a/bin/varnishtest/vtc_misc.c b/bin/varnishtest/vtc_misc.c
index 8a1f80285..060b8e36c 100644
--- a/bin/varnishtest/vtc_misc.c
+++ b/bin/varnishtest/vtc_misc.c
@@ -368,8 +368,6 @@ dns_works(void)
  * the test otherwise; or change the interpretation of the test, as
  * documented below. feature takes any number of arguments from this list:
  *
- * SO_RCVTIMEO_WORKS
- *        The SO_RCVTIMEO socket option is working
  * 64bit
  *        The environment is 64 bits
  * !OSX
@@ -431,13 +429,6 @@ cmd_feature(CMD_ARGS)
 
 	for (av++; *av != NULL; av++) {
 		good = 0;
-		if (!strcmp(*av, "SO_RCVTIMEO_WORKS")) {
-#ifdef SO_RCVTIMEO_WORKS
-			good = 1;
-#else
-			vtc_stop = 2;
-#endif
-		}
 
 		if (!strcmp(*av, "!OSX")) {
 #if !defined(__APPLE__) || !defined(__MACH__)
diff --git a/configure.ac b/configure.ac
index 4d4618ec4..cc6ea4ae4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -491,91 +491,24 @@ AM_MISSING_HAS_RUN
 
 AC_CHECK_DECL([SO_ACCEPTFILTER],
     AC_DEFINE(HAVE_ACCEPT_FILTERS,1,[Define to 1 if you have accept filters]),
-    ,
-    [
-#include <sys/types.h>
-#include <sys/socket.h>
-    ]
-)
-
-# Older Solaris versions define SO_{RCV,SND}TIMEO, but do not
-# implement them.
-#
-# Varnish will build and run without these, but connections will not
-# time out, which may leave Varnish vulnerable to denail-of-service
-# attacks which would not be possible on other platforms.
-#
-# Newer Solaris releases with the Volo framework (Solaris 11,
-# Opensolaris starting with onnv_106) do support SO_{RCV,SND}TIMEO
-# (see PSARC 2007/587, initially committed into onnv-gate /
-# OpenSolaris 8348:4137e18bfaf0 Thu Dec 11 20:04:13 2008)
-
-save_LIBS="${LIBS}"
-LIBS="${LIBS} ${NET_LIBS}"
-AC_CACHE_CHECK([whether SO_RCVTIMEO works],
-  [ac_cv_so_rcvtimeo_works],
-  [AC_RUN_IFELSE(
-    [AC_LANG_PROGRAM([[
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/time.h>
-#include <errno.h>
-    ]],[[
-int s = socket(AF_INET, SOCK_STREAM, 0);
-struct timeval tv = { 1, 0 };
-if (s < 0 && errno == EPROTONOSUPPORT)
-  s = socket(AF_INET6, SOCK_STREAM, 0);
-if (setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof tv) == 0) {
-  socklen_t l = sizeof tv;
-  if (getsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &tv, &l) == 0) {
-    return (l != sizeof tv);
-  }
-}
-return 1;
-    ]])],
-    [ac_cv_so_rcvtimeo_works=yes],
-    [ac_cv_so_rcvtimeo_works=no])
-  ])
-if test "$ac_cv_so_rcvtimeo_works" = yes; then
-   AC_DEFINE([SO_RCVTIMEO_WORKS], [1], [Define if SO_RCVTIMEO works])
-fi
-LIBS="${save_LIBS}"
+    [], [
+        #include <sys/types.h>
+        #include <sys/socket.h>
+    ])
 
-save_LIBS="${LIBS}"
-LIBS="${LIBS} ${NET_LIBS}"
-AC_CACHE_CHECK([whether SO_SNDTIMEO works],
-  [ac_cv_so_sndtimeo_works],
-  [AC_RUN_IFELSE(
-    [AC_LANG_PROGRAM([[
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/time.h>
-#include <errno.h>
-    ]],[[
-int s = socket(AF_INET, SOCK_STREAM, 0);
-struct timeval tv = { 1, 0 };
-if (s < 0 && errno == EPROTONOSUPPORT)
-  s = socket(AF_INET6, SOCK_STREAM, 0);
-if (setsockopt(s, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof tv) == 0) {
-  socklen_t l = sizeof tv;
-  if (getsockopt(s, SOL_SOCKET, SO_SNDTIMEO, &tv, &l) == 0) {
-    return (l != sizeof tv);
-  }
-}
-return 1;
-    ]])],
-    [ac_cv_so_sndtimeo_works=yes],
-    [ac_cv_so_sndtimeo_works=no])
-  ])
-if test "$ac_cv_so_sndtimeo_works" = yes; then
-   AC_DEFINE([SO_SNDTIMEO_WORKS], [1], [Define if SO_SNDTIMEO works])
-fi
+AC_CHECK_DECL([SO_RCVTIMEO],
+    [],
+    AC_MSG_ERROR([SO_RCVTIMEO is needed to build Varnish.]), [
+        #include <sys/types.h>
+        #include <sys/socket.h>
+    ])
 
-if test "$ac_cv_so_rcvtimeo_works" = no ||
-   test "$ac_cv_so_sndtimeo_works" = no; then
-	AC_MSG_WARN([connection timeouts will not work])
-fi
-LIBS="${save_LIBS}"
+AC_CHECK_DECL([SO_SNDTIMEO],
+    [],
+    AC_MSG_ERROR([SO_SNDTIMEO is needed to build Varnish.]), [
+        #include <sys/types.h>
+        #include <sys/socket.h>
+    ])
 
 # Check if the OS supports TCP_KEEP(CNT|IDLE|INTVL) socket options
 save_LIBS="${LIBS}"
diff --git a/include/tbl/params.h b/include/tbl/params.h
index 5fe1e2dd6..053666de4 100644
--- a/include/tbl/params.h
+++ b/include/tbl/params.h
@@ -746,15 +746,6 @@ PARAM(
 	/* func */	NULL
 )
 
-#if defined(XYZZY)
-  #error "Temporary macro XYZZY already defined"
-#endif
-
-#if defined(SO_SNDTIMEO_WORKS)
-  #define XYZZY DELAYED_EFFECT
-#else
-  #define XYZZY NOT_IMPLEMENTED
-#endif
 PARAM(
 	/* name */	idle_send_timeout,
 	/* typ */	timeout,
@@ -762,7 +753,7 @@ PARAM(
 	/* max */	NULL,
 	/* default */	"60.000",
 	/* units */	"seconds",
-	/* flags */	XYZZY,
+	/* flags */	DELAYED_EFFECT,
 	/* s-text */
 	"Send timeout for individual pieces of data on client connections."
 	" May get extended if 'send_timeout' applies.\n\n"
@@ -772,7 +763,6 @@ PARAM(
 	/* l-text */	"",
 	/* func */	NULL
 )
-#undef XYZZY
 
 PARAM(
 	/* name */	listen_depth,
@@ -1010,15 +1000,6 @@ PARAM(
 	/* func */	NULL
 )
 
-#if defined(XYZZY)
-  #error "Temporary macro XYZZY already defined"
-#endif
-
-#if defined(SO_SNDTIMEO_WORKS)
-  #define XYZZY DELAYED_EFFECT
-#else
-  #define XYZZY NOT_IMPLEMENTED
-#endif
 PARAM(
 	/* name */	send_timeout,
 	/* typ */	timeout,
@@ -1026,7 +1007,7 @@ PARAM(
 	/* max */	NULL,
 	/* default */	"600.000",
 	/* units */	"seconds",
-	/* flags */	XYZZY,
+	/* flags */	DELAYED_EFFECT,
 	/* s-text */
 	"Total timeout for ordinary HTTP1 responses. Does not apply to some"
 	" internally generated errors and pipe mode.\n\n"
@@ -1037,7 +1018,6 @@ PARAM(
 	/* l-text */	"",
 	/* func */	NULL
 )
-#undef XYZZY
 
 #if 0
 /* actual location mgt_param_tbl.c */
@@ -1100,6 +1080,9 @@ PARAM(
 	/* func */	NULL
 )
 
+#if defined(XYZZY)
+  #error "Temporary macro XYZZY already defined"
+#endif
 #if defined(HAVE_TCP_FASTOPEN)
   #define XYZZY MUST_RESTART
 #else
@@ -1425,15 +1408,6 @@ PARAM(
 )
 #endif
 
-#if defined(XYZZY)
-  #error "Temporary macro XYZZY already defined"
-#endif
-
-#if defined(SO_RCVTIMEO_WORKS)
-  #define XYZZY 0
-#else
-  #define XYZZY NOT_IMPLEMENTED
-#endif
 PARAM(
 	/* name */	timeout_idle,
 	/* typ */	timeout,
@@ -1441,7 +1415,7 @@ PARAM(
 	/* max */	NULL,
 	/* default */	"5.000",
 	/* units */	"seconds",
-	/* flags */	XYZZY,
+	/* flags */	0,
 	/* s-text */
 	"Idle timeout for client connections.\n\n"
 	"A connection is considered idle until we have received the full"
@@ -1452,7 +1426,6 @@ PARAM(
 	/* l-text */	"",
 	/* func */	NULL
 )
-#undef XYZZY
 
 PARAM(
 	/* name */	timeout_linger,
diff --git a/lib/libvarnish/vtcp.c b/lib/libvarnish/vtcp.c
index b55d91341..602cff69a 100644
--- a/lib/libvarnish/vtcp.c
+++ b/lib/libvarnish/vtcp.c
@@ -349,8 +349,8 @@ VTCP_close(int *s)
 void
 VTCP_set_read_timeout(int s, vtim_dur seconds)
 {
-#ifdef SO_RCVTIMEO_WORKS
 	struct timeval timeout = VTIM_timeval(seconds);
+
 	/*
 	 * Solaris bug (present at least in snv_151 and older): If this fails
 	 * with EINVAL, the socket is half-closed (SS_CANTSENDMORE) and the
@@ -359,10 +359,6 @@ VTCP_set_read_timeout(int s, vtim_dur seconds)
 	 */
 	VTCP_Assert(setsockopt(s, SOL_SOCKET, SO_RCVTIMEO,
 	    &timeout, sizeof timeout));
-#else
-	(void)s;
-	(void)seconds;
-#endif
 }
 
 /*--------------------------------------------------------------------


More information about the varnish-commit mailing list