[master] 0fb88f9fc build: Simply require that SO_???TIMEO are present

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Mon Sep 27 14:00:14 UTC 2021


commit 0fb88f9fc246cff65173ec4d1ecc07ac9b26b711
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 33dc99130..d868e0cac 100644
--- a/bin/varnishd/cache/cache_acceptor.c
+++ b/bin/varnishd/cache/cache_acceptor.c
@@ -94,14 +94,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)
@@ -193,16 +187,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/varnishd/cache/cache_vrt_var.c b/bin/varnishd/cache/cache_vrt_var.c
index 2b05aac01..2294e742c 100644
--- a/bin/varnishd/cache/cache_vrt_var.c
+++ b/bin/varnishd/cache/cache_vrt_var.c
@@ -1000,14 +1000,9 @@ HTTP_VAR(beresp)
 static inline void
 set_idle_send_timeout(const struct sess *sp, VCL_DURATION d)
 {
-#ifdef SO_SNDTIMEO_WORKS
 	struct timeval tv = VTIM_timeval(d);
 	VTCP_Assert(setsockopt(sp->fd, SOL_SOCKET, SO_SNDTIMEO,
 	    &tv, sizeof tv));
-#else
-	(void)sp;
-	(void)d;
-#endif
 }
 
 #define SESS_VAR_DUR(x, setter)				\
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 fd64cb2bd..5948d6bef 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/tests/s00010.vtc b/bin/varnishtest/tests/s00010.vtc
index fea3ea89d..f9e0bbb15 100644
--- a/bin/varnishtest/tests/s00010.vtc
+++ b/bin/varnishtest/tests/s00010.vtc
@@ -3,8 +3,6 @@ varnishtest "client h1 send timeouts - tcp"
 # XXX See https://github.com/varnishcache/varnish-cache/pull/2980#issuecomment-486214661
 feature cmd {test $(uname) != "SunOS" && test $(uname) != "Darwin"}
 
-feature SO_RCVTIMEO_WORKS
-
 barrier b1 cond 2 -cyclic
 barrier b2 cond 2 -cyclic
 
diff --git a/bin/varnishtest/tests/s00012.vtc b/bin/varnishtest/tests/s00012.vtc
index 9726f050f..e635ad03d 100644
--- a/bin/varnishtest/tests/s00012.vtc
+++ b/bin/varnishtest/tests/s00012.vtc
@@ -2,8 +2,6 @@ varnishtest "client h1 send timeouts - uds"
 
 feature cmd {test $(uname) != "SunOS"}
 
-feature SO_RCVTIMEO_WORKS
-
 server s1 {
 	rxreq
 	txresp -bodylen 100000
diff --git a/bin/varnishtest/vtc_misc.c b/bin/varnishtest/vtc_misc.c
index a70d6aa55..59bde405f 100644
--- a/bin/varnishtest/vtc_misc.c
+++ b/bin/varnishtest/vtc_misc.c
@@ -382,8 +382,6 @@ addr_no_randomize_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
  * ipv4
@@ -480,12 +478,6 @@ static const unsigned with_persistent_storage = 1;
 static const unsigned with_persistent_storage = 0;
 #endif
 
-#ifdef SO_RCVTIMEO_WORKS
-static const unsigned so_rcvtimeo_works = 1;
-#else
-static const unsigned so_rcvtimeo_works = 0;
-#endif
-
 void v_matchproto_(cmd_f)
 cmd_feature(CMD_ARGS)
 {
@@ -538,7 +530,6 @@ cmd_feature(CMD_ARGS)
 		FEATURE("tsan", tsan);
 		FEATURE("ubsan", ubsan);
 		FEATURE("sanitizer", sanitizer);
-		FEATURE("SO_RCVTIMEO_WORKS", so_rcvtimeo_works);
 		FEATURE("workspace_emulator", workspace_emulator);
 
 		if (!strcmp(feat, "cmd")) {
diff --git a/configure.ac b/configure.ac
index da9bb0603..ca1a49c29 100644
--- a/configure.ac
+++ b/configure.ac
@@ -532,91 +532,24 @@ AC_CHECK_MEMBER([struct sockaddr.sa_len],
 
 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 denial-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 2cea9074a..270cec0de 100644
--- a/include/tbl/params.h
+++ b/include/tbl/params.h
@@ -610,11 +610,6 @@ PARAM_SIMPLE(
 	"of that the response is allowed to take up."
 )
 
-#if defined(SO_SNDTIMEO_WORKS)
-#  define PLATFORM_FLAGS DELAYED_EFFECT
-#else
-#  define PLATFORM_FLAGS NOT_IMPLEMENTED
-#endif
 PARAM_SIMPLE(
 	/* name */	idle_send_timeout,
 	/* type */	timeout,
@@ -628,9 +623,8 @@ PARAM_SIMPLE(
 	"When this timeout is hit, the session is closed.\n\n"
 	"See the man page for `setsockopt(2)` or `socket(7)` under"
 	" ``SO_SNDTIMEO`` for more information.",
-	/* flags */	PLATFORM_DEPENDENT | PLATFORM_FLAGS
+	/* flags */	DELAYED_EFFECT
 )
-#undef PLATFORM_FLAGS
 
 PARAM_SIMPLE(
 	/* name */	listen_depth,
@@ -781,11 +775,6 @@ PARAM_SIMPLE(
 	/* flags */	EXPERIMENTAL
 )
 
-#if defined(SO_SNDTIMEO_WORKS)
-#  define PLATFORM_FLAGS DELAYED_EFFECT
-#else
-#  define PLATFORM_FLAGS NOT_IMPLEMENTED
-#endif
 PARAM_SIMPLE(
 	/* name */	send_timeout,
 	/* type */	timeout,
@@ -800,9 +789,8 @@ PARAM_SIMPLE(
 	" timeout is extended unless the total time already taken for sending"
 	" the response in its entirety exceeds this many seconds.\n\n"
 	"When this timeout is hit, the session is closed",
-	/* flags */	PLATFORM_DEPENDENT | PLATFORM_FLAGS
+	/* flags */	DELAYED_EFFECT
 )
-#undef PLATFORM_FLAGS
 
 PARAM_SIMPLE(
 	/* name */	shortlived,
@@ -914,11 +902,6 @@ PARAM_SIMPLE(
 )
 #undef PLATFORM_FLAGS
 
-#if defined(SO_RCVTIMEO_WORKS)
-#  define PLATFORM_FLAGS 0
-#else
-#  define PLATFORM_FLAGS NOT_IMPLEMENTED
-#endif
 PARAM_SIMPLE(
 	/* name */	timeout_idle,
 	/* type */	timeout,
@@ -932,10 +915,8 @@ PARAM_SIMPLE(
 	" request headers.\n\n"
 	"This parameter is particularly relevant for HTTP1 keepalive "
 	" connections which are closed unless the next request is received"
-	" before this timeout is reached.",
-	/* flags */	PLATFORM_DEPENDENT | PLATFORM_FLAGS
+	" before this timeout is reached."
 )
-#undef PLATFORM_FLAGS
 
 PARAM_SIMPLE(
 	/* name */	timeout_linger,
diff --git a/lib/libvarnish/vtcp.c b/lib/libvarnish/vtcp.c
index 9e43f5da0..6c1d154a2 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