]> www.infradead.org Git - users/dwmw2/openconnect.git/commitdiff
Use ka_check_deadline() to simplify gpst_mainloop() and esp_mainloop() timers
authorDaniel Lenski <dlenski@gmail.com>
Tue, 9 Jan 2018 08:01:19 +0000 (00:01 -0800)
committerDavid Woodhouse <dwmw2@infradead.org>
Tue, 27 Feb 2018 15:28:32 +0000 (16:28 +0100)
Signed-off-by: Daniel Lenski <dlenski@gmail.com>
Signed-off-by: David Woodhouse <dwmw2@infradead.org>
esp.c
gpst.c
mainloop.c
openconnect-internal.h

diff --git a/esp.c b/esp.c
index 990c1153d122528ea4cf4846494841f8984a6a03..8cf3fc560786b44d6321393817adadac78e35e48 100644 (file)
--- 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 3b73f7e8bca4225c1824f38e6fb14d7447c77650..615dd27a34d716b0488355146bdbd2fb3a19378f 100644 (file)
--- 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 */
index 41245096f707696e476b0ed97352c88331267114..fe185fe205227e9110621e23adbd4b3ee139aee3 100644 (file)
@@ -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;
index ebbf6d28efccbaa4f946056b0143fa46ba6b5fe4..ba81486db0b9d5e27fcea0a3cd35732b1c34d9ac 100644 (file)
@@ -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,