comparison 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
comparison
equal deleted inserted replaced
938:c88dce72f6d2 939:a0819ecfee0b
42 /* process a decrypted packet, call the appropriate handler */ 42 /* process a decrypted packet, call the appropriate handler */
43 void process_packet() { 43 void process_packet() {
44 44
45 unsigned char type; 45 unsigned char type;
46 unsigned int i; 46 unsigned int i;
47 time_t now;
47 48
48 TRACE2(("enter process_packet")) 49 TRACE2(("enter process_packet"))
49 50
50 type = buf_getbyte(ses.payload); 51 type = buf_getbyte(ses.payload);
51 TRACE(("process_packet: packet type = %d, len %d", type, ses.payload->len)) 52 TRACE(("process_packet: packet type = %d, len %d", type, ses.payload->len))
52 53
53 ses.lastpacket = type; 54 ses.lastpacket = type;
54 55
55 ses.last_packet_time = monotonic_now(); 56 now = monotonic_now();
57 ses.last_packet_time_keepalive_recv = now;
56 58
57 /* These packets we can receive at any time */ 59 /* These packets we can receive at any time */
58 switch(type) { 60 switch(type) {
59 61
60 case SSH_MSG_IGNORE: 62 case SSH_MSG_IGNORE:
63 goto out; 65 goto out;
64 66
65 case SSH_MSG_UNIMPLEMENTED: 67 case SSH_MSG_UNIMPLEMENTED:
66 /* debugging XXX */ 68 /* debugging XXX */
67 TRACE(("SSH_MSG_UNIMPLEMENTED")) 69 TRACE(("SSH_MSG_UNIMPLEMENTED"))
68 dropbear_exit("Received SSH_MSG_UNIMPLEMENTED"); 70 goto out;
69 71
70 case SSH_MSG_DISCONNECT: 72 case SSH_MSG_DISCONNECT:
71 /* TODO cleanup? */ 73 /* TODO cleanup? */
72 dropbear_close("Disconnect received"); 74 dropbear_close("Disconnect received");
75 }
76
77 /* Ignore these packet types so that keepalives don't interfere with
78 idle detection. This is slightly incorrect since a tcp forwarded
79 global request with failure won't trigger the idle timeout,
80 but that's probably acceptable */
81 if (!(type == SSH_MSG_GLOBAL_REQUEST || type == SSH_MSG_REQUEST_FAILURE)) {
82 ses.last_packet_time_idle = now;
73 } 83 }
74 84
75 /* This applies for KEX, where the spec says the next packet MUST be 85 /* This applies for KEX, where the spec says the next packet MUST be
76 * NEWKEYS */ 86 * NEWKEYS */
77 if (ses.requirenext != 0) { 87 if (ses.requirenext != 0) {