TCP alwayskeepalive option.

David Malone (dwmalone@maths.tcd.ie)
Thu, 9 Dec 1999 11:15:02 +0000


Some of the BSDs have a net.inet.tcp.always_keepalive option, which
enables keepalives on all tcp connections. We've found this useful
as it seems to keep down the number of catatonic netscapes running
on our servers.

I produced this patch some time ago to add a
/proc/sys/net/ipv4/always_keepalive. I wonder if anyone could
comment on if it should work OK, of if it would be of general
interest? I can reproduce it for a newer kernel if anyone is
interested, but it's a simple patch.

(I did some basic testing on a sparc box with the always_keepalive
both on and off, and the box ran fine. However, before I got to
testing if the keepalives were actually taking effect the box was
reinstalled).

David.

--- ../linux-2.2.5/include/linux/sysctl.h Sun Mar 21 15:22:00 1999
+++ ./linux-2.2.5/include/linux/sysctl.h Mon Apr 12 13:48:49 1999
@@ -209,7 +209,8 @@
NET_IPV4_ICMP_PARAMPROB_RATE=62,
NET_IPV4_ICMP_ECHOREPLY_RATE=63,
NET_IPV4_ICMP_IGNORE_BOGUS_ERROR_RESPONSES=64,
- NET_IPV4_IGMP_MAX_MEMBERSHIPS=65
+ NET_IPV4_IGMP_MAX_MEMBERSHIPS=65,
+ NET_IPV4_TCP_ALWAYS_KEEPALIVE=66
};

enum {
--- ../linux-2.2.5/net/ipv4/tcp_timer.c Tue Mar 23 21:20:34 1999
+++ ./linux-2.2.5/net/ipv4/tcp_timer.c Mon Apr 12 13:52:18 1999
@@ -27,6 +27,7 @@
int sysctl_tcp_keepalive_probes = TCP_KEEPALIVE_PROBES;
int sysctl_tcp_retries1 = TCP_RETR1;
int sysctl_tcp_retries2 = TCP_RETR2;
+int sysctl_tcp_always_keepalive = 0;

static void tcp_sltimer_handler(unsigned long);
static void tcp_syn_recv_timer(unsigned long);
@@ -403,7 +404,7 @@
for(i = chain_start; i < (chain_start + ((TCP_HTABLE_SIZE/2) >> 2)); i++) {
struct sock *sk = tcp_established_hash[i];
while(sk) {
- if(!atomic_read(&sk->sock_readers) && sk->keepopen) {
+ if(!atomic_read(&sk->sock_readers) && (sk->keepopen ||sysctl_tcp_always_keepalive) ) {
count += tcp_keepopen_proc(sk);
if(count == sysctl_tcp_max_ka_probes)
goto out;
--- ../linux-2.2.5/net/ipv4/sysctl_net_ipv4.c Mon Jan 4 23:31:35 1999
+++ ./linux-2.2.5/net/ipv4/sysctl_net_ipv4.c Mon Apr 12 13:51:08 1999
@@ -50,6 +50,7 @@
extern int sysctl_tcp_retrans_collapse;
extern int sysctl_tcp_keepalive_time;
extern int sysctl_tcp_keepalive_probes;
+extern int sysctl_tcp_always_keepalive;
extern int sysctl_tcp_max_ka_probes;
extern int sysctl_tcp_retries1;
extern int sysctl_tcp_retries2;
@@ -93,6 +94,23 @@
return ret;
}

+static
+int ipv4_sysctl_alwayskeepalive(ctl_table *ctl, int write, struct file * filp,
+ void *buffer, size_t *lenp)
+{
+ int val = sysctl_tcp_always_keepalive;
+ int ret;
+
+ ret = proc_dointvec(ctl, write, filp, buffer, lenp);
+
+ if ( val && !sysctl_tcp_always_keepalive)
+ tcp_dec_slow_timer(TCP_SLT_KEEPALIVE);
+ else if( !val && sysctl_tcp_always_keepalive)
+ tcp_inc_slow_timer(TCP_SLT_KEEPALIVE);
+
+ return ret;
+}
+

ctl_table ipv4_table[] = {
{NET_IPV4_TCP_TIMESTAMPS, "tcp_timestamps",
@@ -184,6 +202,9 @@
{NET_IPV4_IGMP_MAX_MEMBERSHIPS, "igmp_max_memberships",
&sysctl_igmp_max_memberships, sizeof(int), 0644, NULL, &proc_dointvec},
#endif
+ {NET_IPV4_TCP_ALWAYS_KEEPALIVE, "always_keepalive",
+ &sysctl_tcp_always_keepalive, sizeof(int), 0644, NULL,
+ &ipv4_sysctl_alwayskeepalive},
{0}
};

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/