From: Daniel Lenski Date: Tue, 9 Jan 2018 08:01:19 +0000 (-0800) Subject: Use ka_check_deadline() to simplify gpst_mainloop() and esp_mainloop() timers X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=ed87a2a7720abb991182c3d16379a6b6017a1abb;p=users%2Fdwmw2%2Fopenconnect.git Use ka_check_deadline() to simplify gpst_mainloop() and esp_mainloop() timers Signed-off-by: Daniel Lenski Signed-off-by: David Woodhouse --- diff --git a/esp.c b/esp.c index 990c1153..8cf3fc56 100644 --- a/esp.c +++ b/esp.c @@ -103,15 +103,12 @@ int esp_mainloop(struct openconnect_info *vpninfo, int *timeout) int ret; if (vpninfo->dtls_state == DTLS_SLEEPING) { - int when = vpninfo->new_dtls_started + vpninfo->dtls_attempt_period - time(NULL); - if (when <= 0 || vpninfo->dtls_need_reconnect) { + if (ka_check_deadline(timeout, time(NULL), vpninfo->new_dtls_started + vpninfo->dtls_attempt_period) + || vpninfo->dtls_need_reconnect) { vpn_progress(vpninfo, PRG_DEBUG, _("Send ESP probes\n")); if (vpninfo->proto->udp_send_probes) vpninfo->proto->udp_send_probes(vpninfo); - when = vpninfo->dtls_attempt_period; } - if (*timeout > when * 1000) - *timeout = when * 1000; } if (vpninfo->dtls_fd == -1) return 0; diff --git a/gpst.c b/gpst.c index 3b73f7e8..615dd27a 100644 --- a/gpst.c +++ b/gpst.c @@ -911,10 +911,8 @@ int gpst_mainloop(struct openconnect_info *vpninfo, int *timeout) return 0; case DTLS_SECRET: case DTLS_SLEEPING: - if (time(NULL) < vpninfo->dtls_times.last_rekey + 5) { + if (!ka_check_deadline(timeout, time(NULL), vpninfo->dtls_times.last_rekey + 5)) { /* Allow 5 seconds after configuration for ESP to start */ - if (*timeout > 5000) - *timeout = 5000; return 0; } else if (!vpninfo->ssl_times.last_rekey) { /* ... before we switch to HTTPS instead */ diff --git a/mainloop.c b/mainloop.c index 41245096..fe185fe2 100644 --- a/mainloop.c +++ b/mainloop.c @@ -315,7 +315,7 @@ int openconnect_mainloop(struct openconnect_info *vpninfo, return ret < 0 ? ret : -EIO; } -static int ka_check_deadline(int *timeout, time_t now, time_t due) +int ka_check_deadline(int *timeout, time_t now, time_t due) { if (now >= due) return 1; diff --git a/openconnect-internal.h b/openconnect-internal.h index ebbf6d28..ba81486d 100644 --- a/openconnect-internal.h +++ b/openconnect-internal.h @@ -964,6 +964,7 @@ int tun_mainloop(struct openconnect_info *vpninfo, int *timeout); int queue_new_packet(struct pkt_q *q, void *buf, int len); int keepalive_action(struct keepalive_info *ka, int *timeout); int ka_stalled_action(struct keepalive_info *ka, int *timeout); +int ka_check_deadline(int *timeout, time_t now, time_t due); /* xml.c */ ssize_t read_file_into_string(struct openconnect_info *vpninfo, const char *fname,