diff process-packet.c @ 939:a0819ecfee0b

Make -K keepalive behave like OpenSSH's ServerAliveInterval
author Matt Johnston <matt@ucc.asn.au>
date Wed, 09 Jul 2014 00:15:20 +0800
parents 7cd89d4e0335
children 73ea0dce9a57 9169e4e7cbee
line wrap: on
line diff
--- a/process-packet.c	Wed Jul 09 00:13:17 2014 +0800
+++ b/process-packet.c	Wed Jul 09 00:15:20 2014 +0800
@@ -44,6 +44,7 @@
 
 	unsigned char type;
 	unsigned int i;
+	time_t now;
 
 	TRACE2(("enter process_packet"))
 
@@ -52,7 +53,8 @@
 
 	ses.lastpacket = type;
 
-	ses.last_packet_time = monotonic_now();
+	now = monotonic_now();
+	ses.last_packet_time_keepalive_recv = now;
 
 	/* These packets we can receive at any time */
 	switch(type) {
@@ -65,13 +67,21 @@
 		case SSH_MSG_UNIMPLEMENTED:
 			/* debugging XXX */
 			TRACE(("SSH_MSG_UNIMPLEMENTED"))
-			dropbear_exit("Received SSH_MSG_UNIMPLEMENTED");
+			goto out;
 			
 		case SSH_MSG_DISCONNECT:
 			/* TODO cleanup? */
 			dropbear_close("Disconnect received");
 	}
 
+	/* Ignore these packet types so that keepalives don't interfere with
+	idle detection. This is slightly incorrect since a tcp forwarded
+	global request with failure won't trigger the idle timeout,
+	but that's probably acceptable */
+	if (!(type == SSH_MSG_GLOBAL_REQUEST || type == SSH_MSG_REQUEST_FAILURE)) {
+		ses.last_packet_time_idle = now;
+	}
+
 	/* This applies for KEX, where the spec says the next packet MUST be
 	 * NEWKEYS */
 	if (ses.requirenext != 0) {