comparison common-session.c @ 1140:f6d3a16ecc71

set timeouts to time remaining rather than timeout duration
author Matt Johnston <matt@ucc.asn.au>
date Mon, 03 Aug 2015 23:05:43 +0800
parents 43a8ea69b24c
children 924ff1b959a2
comparison
equal deleted inserted replaced
1139:43a8ea69b24c 1140:f6d3a16ecc71
530 && now - ses.last_packet_time_idle >= opts.idle_timeout_secs) { 530 && now - ses.last_packet_time_idle >= opts.idle_timeout_secs) {
531 dropbear_close("Idle timeout"); 531 dropbear_close("Idle timeout");
532 } 532 }
533 } 533 }
534 534
535 static void update_timeout(long limit, long now, long last_event, long * timeout) {
536 TRACE(("update_timeout limit %ld, now %ld, last %ld, timeout %ld",
537 limit, now, last_event, *timeout))
538 if (last_event > 0 && limit > 0) {
539 *timeout = MIN(*timeout, last_event+limit-now);
540 TRACE(("update to %ld", *timeout))
541 }
542 }
543
535 static long select_timeout() { 544 static long select_timeout() {
536 /* determine the minimum timeout that might be required, so 545 /* determine the minimum timeout that might be required, so
537 as to avoid waking when unneccessary */ 546 as to avoid waking when unneccessary */
538 long ret = LONG_MAX; 547 long timeout = LONG_MAX;
539 if (KEX_REKEY_TIMEOUT > 0) 548 long now = monotonic_now();
540 ret = MIN(KEX_REKEY_TIMEOUT, ret); 549
541 /* AUTH_TIMEOUT is only relevant before authdone */ 550 update_timeout(KEX_REKEY_TIMEOUT, now, ses.kexstate.lastkextime, &timeout);
542 if (ses.authstate.authdone != 1 && AUTH_TIMEOUT > 0) 551
543 ret = MIN(AUTH_TIMEOUT, ret); 552 if (ses.authstate.authdone != 1 && IS_DROPBEAR_SERVER) {
544 if (opts.keepalive_secs > 0) 553 /* AUTH_TIMEOUT is only relevant before authdone */
545 ret = MIN(opts.keepalive_secs, ret); 554 update_timeout(AUTH_TIMEOUT, now, ses.connect_time, &timeout);
546 if (opts.idle_timeout_secs > 0) 555 }
547 ret = MIN(opts.idle_timeout_secs, ret); 556
548 return ret; 557 update_timeout(opts.keepalive_secs, now,
558 MAX(ses.last_packet_time_keepalive_recv, ses.last_packet_time_keepalive_sent),
559 &timeout);
560
561 update_timeout(opts.idle_timeout_secs, now, ses.last_packet_time_idle,
562 &timeout);
563
564 TRACE(("timeout %ld", timeout))
565
566 /* clamp negative timeouts to zero - event has already triggered */
567 return MAX(timeout, 0);
549 } 568 }
550 569
551 const char* get_user_shell() { 570 const char* get_user_shell() {
552 /* an empty shell should be interpreted as "/bin/sh" */ 571 /* an empty shell should be interpreted as "/bin/sh" */
553 if (ses.authstate.pw_shell[0] == '\0') { 572 if (ses.authstate.pw_shell[0] == '\0') {