Commit 254faf07 authored by Dridi Boukelmoune's avatar Dridi Boukelmoune

build: Simply require that SO_???TIMEO are present

Closes #3692

Conflicts:
	bin/varnishd/cache/cache_acceptor.c
parent 6093812b
......@@ -100,12 +100,8 @@ static struct sock_opt {
SOCK_OPT(SOL_SOCKET, SO_LINGER, struct linger)
SOCK_OPT(SOL_SOCKET, SO_KEEPALIVE, int)
#ifdef SO_SNDTIMEO_WORKS
SOCK_OPT(SOL_SOCKET, SO_SNDTIMEO, struct timeval)
#endif
#ifdef SO_RCVTIMEO_WORKS
SOCK_OPT(SOL_SOCKET, SO_RCVTIMEO, struct timeval)
#endif
SOCK_OPT(IPPROTO_TCP, TCP_NODELAY, int)
#ifdef HAVE_TCP_KEEP
......@@ -204,14 +200,10 @@ vca_sock_opt_init(void)
SET_VAL(SO_LINGER, so, lg, disable_so_linger);
SET_VAL(SO_KEEPALIVE, so, i, enable_so_keepalive);
#ifdef SO_SNDTIMEO_WORKS
NEW_VAL(SO_SNDTIMEO, so, tv,
VTIM_timeval(cache_param->idle_send_timeout));
#endif
#ifdef SO_RCVTIMEO_WORKS
NEW_VAL(SO_RCVTIMEO, so, tv,
VTIM_timeval(cache_param->timeout_idle));
#endif
SET_VAL(TCP_NODELAY, so, i, enable_tcp_nodelay);
#ifdef HAVE_TCP_KEEP
NEW_VAL(TCP_KEEPIDLE, so, i,
......
......@@ -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) \
......
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"
......
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"
......
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"
......
varnishtest "Check that the first_byte_timeout works"
feature SO_RCVTIMEO_WORKS
# From VCL
server s1 {
......
varnishtest "Check the precedence for timeouts"
feature SO_RCVTIMEO_WORKS
server s1 {
rxreq
expect req.url == "from_backend"
......
......@@ -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
......
......@@ -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
......
......@@ -410,8 +410,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
......@@ -508,12 +506,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)
{
......@@ -566,7 +558,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")) {
......
......@@ -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}"
......
......@@ -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,
......
......@@ -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
}
/*--------------------------------------------------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment