Add packaging
[platform/upstream/openconnect.git] / mainloop.c
index 5a65c51..2d10147 100644 (file)
 #include <poll.h>
 #include <limits.h>
 #include <sys/select.h>
+#include <stdlib.h>
 #include <signal.h>
 #include <unistd.h>
 #include <string.h>
 
-#include <openssl/ssl.h>
-
 #include "openconnect-internal.h"
 
 void queue_packet(struct pkt **q, struct pkt *new)
@@ -79,7 +78,7 @@ int vpn_mainloop(struct openconnect_info *vpninfo)
                struct timeval tv;
                fd_set rfds, wfds, efds;
 
-#ifdef SSL_OP_CISCO_ANYCONNECT
+#ifdef HAVE_DTLS
                if (vpninfo->new_dtls_ssl)
                        dtls_try_handshake(vpninfo);
 
@@ -137,23 +136,32 @@ int vpn_mainloop(struct openconnect_info *vpninfo)
 
 /* Called when the socket is unwritable, to get the deadline for DPD.
    Returns 1 if DPD deadline has already arrived. */
-int ka_stalled_dpd_time(struct keepalive_info *ka, int *timeout)
+int ka_stalled_action(struct keepalive_info *ka, int *timeout)
 {
-       time_t now, due;
+       time_t due, now = time(NULL);
+
+       if (ka->rekey) {
+               due = ka->last_rekey + ka->rekey;
+
+               if (now >= due)
+                       return KA_REKEY;
+
+               if (*timeout > (due - now) * 1000)
+                       *timeout = (due - now) * 1000;
+       }
 
        if (!ka->dpd)
-               return 0;
+               return KA_NONE;
 
-       time(&now);
        due = ka->last_rx + (2 * ka->dpd);
 
        if (now > due)
-               return 1;
+               return KA_DPD_DEAD;
 
        if (*timeout > (due - now) * 1000)
                *timeout = (due - now) * 1000;
 
-       return 0;
+       return KA_NONE;
 }