summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsthen <sthen@openbsd.org>2011-07-06 23:44:20 +0000
committersthen <sthen@openbsd.org>2011-07-06 23:44:20 +0000
commit04c823f3c14a1d85985bdd950c5559067538cec9 (patch)
tree8da6dfaad9ef6304270558ce982d274c4441d135
parentHandle pci_conf_read() faults on reading non-existent registers that result (diff)
downloadwireguard-openbsd-04c823f3c14a1d85985bdd950c5559067538cec9.tar.xz
wireguard-openbsd-04c823f3c14a1d85985bdd950c5559067538cec9.zip
Add sysctl net.inet.tcp.always_keepalive, when this is set the system
behaves as if SO_KEEPALIVE was set on all TCP sockets, forcing keepalives to be sent every net.inet.tcp.keepidle half-seconds. In conjunction with a keepidle value greatly reduced from the default, this can be useful for keeping sessions open if you are stuck on a network with short NAT or firewall timeouts. Feedback from various people, ok henning@ claudio@
-rw-r--r--lib/libc/gen/sysctl.38
-rw-r--r--sbin/sysctl/sysctl.85
-rw-r--r--sys/netinet/tcp_timer.c6
-rw-r--r--sys/netinet/tcp_timer.h3
-rw-r--r--sys/netinet/tcp_usrreq.c6
-rw-r--r--sys/netinet/tcp_var.h8
6 files changed, 25 insertions, 11 deletions
diff --git a/lib/libc/gen/sysctl.3 b/lib/libc/gen/sysctl.3
index 5fd5f847fee..fd04ac0dbfc 100644
--- a/lib/libc/gen/sysctl.3
+++ b/lib/libc/gen/sysctl.3
@@ -1,4 +1,4 @@
-.\" $OpenBSD: sysctl.3,v 1.203 2011/06/27 17:43:03 naddy Exp $
+.\" $OpenBSD: sysctl.3,v 1.204 2011/07/06 23:44:20 sthen Exp $
.\"
.\" Copyright (c) 1993
.\" The Regents of the University of California. All rights reserved.
@@ -27,7 +27,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd $Mdocdate: June 27 2011 $
+.Dd $Mdocdate: July 6 2011 $
.Dt SYSCTL 3
.Os
.Sh NAME
@@ -1575,6 +1575,10 @@ Time to keep alive the initial SYN packet of a TCP handshake.
Time after a keepalive probe is sent until, in the absence of any response,
another probe is sent.
See also tcp.slowhz.
+.It Li tcp.always_keepalive
+Act as if the option
+.Dv SO_KEEPALIVE
+was set on all TCP sockets.
.It Li tcp.mssdflt
The maximum segment size that is used as default for non-local connections.
The default value is 512.
diff --git a/sbin/sysctl/sysctl.8 b/sbin/sysctl/sysctl.8
index 238048037f5..6bb7064dba1 100644
--- a/sbin/sysctl/sysctl.8
+++ b/sbin/sysctl/sysctl.8
@@ -1,4 +1,4 @@
-.\" $OpenBSD: sysctl.8,v 1.159 2011/06/24 19:47:48 naddy Exp $
+.\" $OpenBSD: sysctl.8,v 1.160 2011/07/06 23:44:20 sthen Exp $
.\" $NetBSD: sysctl.8,v 1.4 1995/09/30 07:12:49 thorpej Exp $
.\"
.\" Copyright (c) 1993
@@ -30,7 +30,7 @@
.\"
.\" @(#)sysctl.8 8.2 (Berkeley) 5/9/95
.\"
-.Dd $Mdocdate: June 24 2011 $
+.Dd $Mdocdate: July 6 2011 $
.Dt SYSCTL 8
.Os
.Sh NAME
@@ -257,6 +257,7 @@ and a few require a kernel compiled with non-standard
.It net.inet.tcp.keepinittime integer yes
.It net.inet.tcp.keepidle integer yes
.It net.inet.tcp.keepintvl integer yes
+.It net.inet.tcp.always_keepalive integer yes
.It net.inet.tcp.slowhz integer no
.It net.inet.tcp.baddynamic array yes
.It net.inet.tcp.sack integer yes
diff --git a/sys/netinet/tcp_timer.c b/sys/netinet/tcp_timer.c
index a1dd72aae79..7f2511d751a 100644
--- a/sys/netinet/tcp_timer.c
+++ b/sys/netinet/tcp_timer.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tcp_timer.c,v 1.45 2010/07/03 04:44:51 guenther Exp $ */
+/* $OpenBSD: tcp_timer.c,v 1.46 2011/07/06 23:44:20 sthen Exp $ */
/* $NetBSD: tcp_timer.c,v 1.14 1996/02/13 23:44:09 christos Exp $ */
/*
@@ -55,6 +55,7 @@
#include <netinet/ip_icmp.h>
#include <netinet/tcp_seq.h>
+int tcp_always_keepalive;
int tcp_keepidle;
int tcp_keepintvl;
int tcp_maxpersistidle; /* max idle time in persist */
@@ -435,7 +436,8 @@ tcp_timer_keep(void *arg)
tcpstat.tcps_keeptimeo++;
if (TCPS_HAVEESTABLISHED(tp->t_state) == 0)
goto dropit;
- if (tp->t_inpcb->inp_socket->so_options & SO_KEEPALIVE &&
+ if ((tcp_always_keepalive ||
+ tp->t_inpcb->inp_socket->so_options & SO_KEEPALIVE) &&
tp->t_state <= TCPS_CLOSING) {
if ((tcp_maxidle > 0) &&
((tcp_now - tp->t_rcvtime) >= tcp_keepidle + tcp_maxidle))
diff --git a/sys/netinet/tcp_timer.h b/sys/netinet/tcp_timer.h
index 6f0dceda02a..67daccdfb32 100644
--- a/sys/netinet/tcp_timer.h
+++ b/sys/netinet/tcp_timer.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tcp_timer.h,v 1.12 2008/11/08 12:54:58 dlg Exp $ */
+/* $OpenBSD: tcp_timer.h,v 1.13 2011/07/06 23:44:20 sthen Exp $ */
/* $NetBSD: tcp_timer.h,v 1.6 1995/03/26 20:32:37 jtc Exp $ */
/*
@@ -145,6 +145,7 @@ typedef void (*tcp_timer_func_t)(void *);
extern const tcp_timer_func_t tcp_timer_funcs[TCPT_NTIMERS];
extern int tcptv_keep_init;
+extern int tcp_always_keepalive; /* assume SO_KEEPALIVE is always set */
extern int tcp_keepidle; /* time before keepalive probes begin */
extern int tcp_keepintvl; /* time between keepalive probes */
extern int tcp_maxidle; /* time to drop after starting probes */
diff --git a/sys/netinet/tcp_usrreq.c b/sys/netinet/tcp_usrreq.c
index 2e14907f448..6f70aaf3184 100644
--- a/sys/netinet/tcp_usrreq.c
+++ b/sys/netinet/tcp_usrreq.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tcp_usrreq.c,v 1.107 2011/04/28 09:56:27 claudio Exp $ */
+/* $OpenBSD: tcp_usrreq.c,v 1.108 2011/07/06 23:44:20 sthen Exp $ */
/* $NetBSD: tcp_usrreq.c,v 1.20 1996/02/13 23:44:16 christos Exp $ */
/*
@@ -909,6 +909,10 @@ tcp_sysctl(name, namelen, oldp, oldlenp, newp, newlen)
case TCPCTL_DROP:
return (tcp_ident(oldp, oldlenp, newp, newlen, 1));
+ case TCPCTL_ALWAYS_KEEPALIVE:
+ return (sysctl_int(oldp, oldlenp, newp, newlen,
+ &tcp_always_keepalive));
+
#ifdef TCP_ECN
case TCPCTL_ECN:
return (sysctl_int(oldp, oldlenp, newp, newlen,
diff --git a/sys/netinet/tcp_var.h b/sys/netinet/tcp_var.h
index 0573c7d966b..7a61253231f 100644
--- a/sys/netinet/tcp_var.h
+++ b/sys/netinet/tcp_var.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tcp_var.h,v 1.98 2011/01/07 17:50:42 bluhm Exp $ */
+/* $OpenBSD: tcp_var.h,v 1.99 2011/07/06 23:44:20 sthen Exp $ */
/* $NetBSD: tcp_var.h,v 1.17 1996/02/13 23:44:24 christos Exp $ */
/*
@@ -473,7 +473,8 @@ struct tcpstat {
#define TCPCTL_DROP 19 /* drop tcp connection */
#define TCPCTL_SACKHOLE_LIMIT 20 /* max entries for tcp sack queues */
#define TCPCTL_STATS 21 /* TCP statistics */
-#define TCPCTL_MAXID 22
+#define TCPCTL_ALWAYS_KEEPALIVE 22 /* assume SO_KEEPALIVE is always set */
+#define TCPCTL_MAXID 23
#define TCPCTL_NAMES { \
{ 0, 0 }, \
@@ -497,7 +498,8 @@ struct tcpstat {
{ "reasslimit", CTLTYPE_INT }, \
{ "drop", CTLTYPE_STRUCT }, \
{ "sackholelimit", CTLTYPE_INT }, \
- { "stats", CTLTYPE_STRUCT } \
+ { "stats", CTLTYPE_STRUCT }, \
+ { "always_keepalive", CTLTYPE_INT } \
}
#define TCPCTL_VARS { \