diff common-session.c @ 493:6cd2152aae0b idle-timeout

Idle-timeout patch from Farrell Aultman, need to figure whether to only account DATA packets and whether server->client data makes sense too.
author Matt Johnston <matt@ucc.asn.au>
date Mon, 22 Sep 2008 15:28:52 +0000
parents 738313e73b1c
children
line wrap: on
line diff
--- a/common-session.c	Mon Sep 22 14:13:44 2008 +0000
+++ b/common-session.c	Mon Sep 22 15:28:52 2008 +0000
@@ -64,6 +64,7 @@
 
 	ses.connect_time = 0;
 	ses.last_packet_time = 0;
+	ses.last_recv_packet_time = 0;
 	
 	if (pipe(ses.signal_pipe) < 0) {
 		dropbear_exit("signal pipe failed");
@@ -256,7 +257,7 @@
 		ses.remoteclosed();
 	}
 
-    /* If they send more than 50 lines, something is wrong */
+	/* If they send more than 50 lines, something is wrong */
 	for (i = 0; i < 50; i++) {
 		len = ident_readln(ses.sock_in, linebuf, sizeof(linebuf));
 
@@ -281,11 +282,11 @@
 		memcpy(ses.remoteident, linebuf, len);
 	}
 
-    /* Shall assume that 2.x will be backwards compatible. */
-    if (strncmp(ses.remoteident, "SSH-2.", 6) != 0
-            && strncmp(ses.remoteident, "SSH-1.99-", 9) != 0) {
-        dropbear_exit("Incompatible remote version '%s'", ses.remoteident);
-    }
+	/* Shall assume that 2.x will be backwards compatible. */
+	if (strncmp(ses.remoteident, "SSH-2.", 6) != 0
+			&& strncmp(ses.remoteident, "SSH-1.99-", 9) != 0) {
+		dropbear_exit("Incompatible remote version '%s'", ses.remoteident);
+	}
 
 	TRACE(("remoteident: %s", ses.remoteident))
 
@@ -400,6 +401,11 @@
 		&& now - ses.last_packet_time >= opts.keepalive_secs) {
 		send_msg_ignore();
 	}
+
+	if (opts.idle_timeout_secs > 0 && ses.last_recv_packet_time > 0
+			&& now - ses.last_recv_packet_time >= opts.idle_timeout_secs) {
+		dropbear_close("Idle timeout");
+	}
 }
 
 static long select_timeout() {
@@ -412,6 +418,8 @@
 		ret = MIN(AUTH_TIMEOUT, ret);
 	if (opts.keepalive_secs > 0)
 		ret = MIN(opts.keepalive_secs, ret);
+	if (opts.idle_timeout_secs > 0)
+		ret = MIN(opts.idle_timeout_secs, ret);
 	return ret;
 }