summaryrefslogtreecommitdiff
path: root/serverloop.c
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2016-03-04 03:35:44 +0000
committerDamien Miller <djm@mindrot.org>2016-03-04 15:12:21 +1100
commit988e429d903acfb298bfddfd75e7994327adfed0 (patch)
tree467226f3c566d260181c2379637b378681d2581c /serverloop.c
parent8ef04d7a94bcdb8b0085fdd2a79a844b7d40792d (diff)
upstream commit
fix ClientAliveInterval when a time-based RekeyLimit is set; previously keepalive packets were not being sent. bz#2252 report and analysis by Christian Wittenhorst and Garrett Lee feedback and ok dtucker@ Upstream-ID: d48f9deadd35fdacdd5106b41bb07630ddd4aa81
Diffstat (limited to 'serverloop.c')
-rw-r--r--serverloop.c28
1 files changed, 15 insertions, 13 deletions
diff --git a/serverloop.c b/serverloop.c
index 80d1db549..e6a92476f 100644
--- a/serverloop.c
+++ b/serverloop.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: serverloop.c,v 1.182 2016/02/08 10:57:07 djm Exp $ */ 1/* $OpenBSD: serverloop.c,v 1.183 2016/03/04 03:35:44 djm Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -276,7 +276,7 @@ client_alive_check(void)
276 */ 276 */
277static void 277static void
278wait_until_can_do_something(fd_set **readsetp, fd_set **writesetp, int *maxfdp, 278wait_until_can_do_something(fd_set **readsetp, fd_set **writesetp, int *maxfdp,
279 u_int *nallocp, u_int64_t max_time_milliseconds) 279 u_int *nallocp, u_int64_t max_time_ms)
280{ 280{
281 struct timeval tv, *tvp; 281 struct timeval tv, *tvp;
282 int ret; 282 int ret;
@@ -288,9 +288,9 @@ wait_until_can_do_something(fd_set **readsetp, fd_set **writesetp, int *maxfdp,
288 channel_prepare_select(readsetp, writesetp, maxfdp, nallocp, 288 channel_prepare_select(readsetp, writesetp, maxfdp, nallocp,
289 &minwait_secs, 0); 289 &minwait_secs, 0);
290 290
291 /* XXX need proper deadline system for rekey/client alive */
291 if (minwait_secs != 0) 292 if (minwait_secs != 0)
292 max_time_milliseconds = MIN(max_time_milliseconds, 293 max_time_ms = MIN(max_time_ms, (u_int)minwait_secs * 1000);
293 (u_int)minwait_secs * 1000);
294 294
295 /* 295 /*
296 * if using client_alive, set the max timeout accordingly, 296 * if using client_alive, set the max timeout accordingly,
@@ -300,11 +300,13 @@ wait_until_can_do_something(fd_set **readsetp, fd_set **writesetp, int *maxfdp,
300 * this could be randomized somewhat to make traffic 300 * this could be randomized somewhat to make traffic
301 * analysis more difficult, but we're not doing it yet. 301 * analysis more difficult, but we're not doing it yet.
302 */ 302 */
303 if (compat20 && 303 if (compat20 && options.client_alive_interval) {
304 max_time_milliseconds == 0 && options.client_alive_interval) { 304 uint64_t keepalive_ms =
305 (uint64_t)options.client_alive_interval * 1000;
306
305 client_alive_scheduled = 1; 307 client_alive_scheduled = 1;
306 max_time_milliseconds = 308 if (max_time_ms == 0 || max_time_ms > keepalive_ms)
307 (u_int64_t)options.client_alive_interval * 1000; 309 max_time_ms = keepalive_ms;
308 } 310 }
309 311
310 if (compat20) { 312 if (compat20) {
@@ -353,14 +355,14 @@ wait_until_can_do_something(fd_set **readsetp, fd_set **writesetp, int *maxfdp,
353 * from it, then read as much as is available and exit. 355 * from it, then read as much as is available and exit.
354 */ 356 */
355 if (child_terminated && packet_not_very_much_data_to_write()) 357 if (child_terminated && packet_not_very_much_data_to_write())
356 if (max_time_milliseconds == 0 || client_alive_scheduled) 358 if (max_time_ms == 0 || client_alive_scheduled)
357 max_time_milliseconds = 100; 359 max_time_ms = 100;
358 360
359 if (max_time_milliseconds == 0) 361 if (max_time_ms == 0)
360 tvp = NULL; 362 tvp = NULL;
361 else { 363 else {
362 tv.tv_sec = max_time_milliseconds / 1000; 364 tv.tv_sec = max_time_ms / 1000;
363 tv.tv_usec = 1000 * (max_time_milliseconds % 1000); 365 tv.tv_usec = 1000 * (max_time_ms % 1000);
364 tvp = &tv; 366 tvp = &tv;
365 } 367 }
366 368