]> www.infradead.org Git - users/dwmw2/openconnect.git/commitdiff
add protocol-agnostic idle_timeout and openconnect_get_idle_timeout() API function
authorDaniel Lenski <dlenski@gmail.com>
Mon, 6 Aug 2018 20:06:07 +0000 (13:06 -0700)
committerDaniel Lenski <dlenski@gmail.com>
Mon, 6 Aug 2018 20:08:33 +0000 (13:08 -0700)
This is needed for the Android GUI to detect the idle/keepalive interval in a cross-protocol way.

cstp.c
gpst.c
java/src/com/example/LibTest.java
java/src/org/infradead/libopenconnect/LibOpenConnect.java
jni.c
libopenconnect.map.in
library.c
openconnect-internal.h
openconnect.h

diff --git a/cstp.c b/cstp.c
index 8cca637a5d45e6c465b9c183861d6254d855d6e2..68c3d51119abd421ff9ef716edea28b7ca39d9ad 100644 (file)
--- a/cstp.c
+++ b/cstp.c
@@ -462,6 +462,8 @@ static int start_cstp_connection(struct openconnect_info *vpninfo)
 
                if (!strcmp(buf + 7, "Keepalive")) {
                        vpninfo->ssl_times.keepalive = atol(colon);
+               } else if (!strcmp(buf + 7, "Idle-Timeout")) {
+                       vpninfo->idle_timeout = atol(colon);
                } else if (!strcmp(buf + 7, "DPD")) {
                        int j = atol(colon);
                        if (j && (!vpninfo->ssl_times.dpd || j < vpninfo->ssl_times.dpd))
diff --git a/gpst.c b/gpst.c
index a396aa6934e5d12eb4228f8fbf878bfe66293d34..9742fe1679a8d9d83bb208b2f21ea83240e679a3 100644 (file)
--- a/gpst.c
+++ b/gpst.c
@@ -481,6 +481,11 @@ static int gpst_parse_config_xml(struct openconnect_info *vpninfo, xmlNode *xml_
                else if (!xmlnode_get_text(xml_node, "mtu", &s)) {
                        vpninfo->ip_info.mtu = atoi(s);
                        free(s);
+               } else if (!xmlnode_get_text(xml_node, "disconnect-on-idle", &s)) {
+                       int sec = atoi(s);
+                       vpn_progress(vpninfo, PRG_INFO, _("Idle timeout is %d minutes.\n"), sec/60);
+                       vpninfo->idle_timeout = sec;
+                       free(s);
                } else if (!xmlnode_get_text(xml_node, "ssl-tunnel-url", &s)) {
                        free(vpninfo->urlpath);
                        vpninfo->urlpath = s;
index 44f4312c3bee23a954e87b2b002111fee8c0b35d..034e450ebc3f802c1849738dd26908377c608815 100644 (file)
@@ -275,6 +275,8 @@ public final class LibTest {
                if (lib.makeCSTPConnection() != 0)
                        die("Error establishing VPN link");
 
+               int idleTimeout = lib.getIdleTimeout();
+               System.out.println("Idle Timeout: " + idleTimeout + " seconds");
                printIPInfo(lib.getIPInfo());
 
                if (lib.setupDTLS(60) != 0)
index c580f9915d0db175d2a112be679b04326bc5d1fa..1ba7b420cc22dfcce0ff30336687cc8236c2f11d 100644 (file)
@@ -157,6 +157,7 @@ public abstract class LibOpenConnect {
        public synchronized native String getCSTPCompression();
        public synchronized native String getDTLSCompression();
        public synchronized native String getProtocol();
+       public synchronized native int getIdleTimeout();
 
        /* certificate info */
 
@@ -247,6 +248,7 @@ public abstract class LibOpenConnect {
                public String proxyPac;
                public String gatewayAddr;
                public int MTU;
+               public int idleTimeoutSec;
 
                public ArrayList<String> splitDNS = new ArrayList<String>();
                public ArrayList<String> splitIncludes = new ArrayList<String>();
diff --git a/jni.c b/jni.c
index c377a5cf38e83809938ffd8b3623488fc1110181..be170bcc1652b36be36766e48f8eb7d506db23bb 100644 (file)
--- a/jni.c
+++ b/jni.c
@@ -1108,6 +1108,16 @@ JNIEXPORT void JNICALL Java_org_infradead_libopenconnect_LibOpenConnect_setXMLPo
        openconnect_set_xmlpost(ctx->vpninfo, arg);
 }
 
+JNIEXPORT jint JNICALL Java_org_infradead_libopenconnect_LibOpenConnect_getIdleTimeout(
+       JNIEnv *jenv, jobject jobj)
+{
+       struct libctx *ctx = getctx(jenv, jobj);
+
+       if (!ctx)
+               return -EINVAL;
+       return openconnect_get_idle_timeout(ctx->vpninfo);
+}
+
 /* simple cases: return a const string (no need to free it) */
 
 #define RETURN_STRING_START \
index 0f4ccd05cce3c7cac1fcb53de6f1c7bb56eaa61e..1f29726874009548a0bc246435abd80d12617b6d 100644 (file)
@@ -94,6 +94,7 @@ OPENCONNECT_5_4 {
 
 OPENCONNECT_5_5 {
  global:
+       openconnect_get_idle_timeout;
        openconnect_get_protocol;
        openconnect_get_supported_protocols;
        openconnect_free_supported_protocols;
index c1474609d0c41615861e724004c076b489f04bdc..3d134995f51bd2a59658e74d744703e464f26d5f 100644 (file)
--- a/library.c
+++ b/library.c
@@ -538,6 +538,11 @@ void openconnect_set_dpd(struct openconnect_info *vpninfo, int min_seconds)
                vpninfo->dtls_times.dpd = vpninfo->ssl_times.dpd = 2;
 }
 
+int openconnect_get_idle_timeout(struct openconnect_info *vpninfo)
+{
+       return vpninfo->idle_timeout;
+}
+
 int openconnect_get_ip_info(struct openconnect_info *vpninfo,
                            const struct oc_ip_info **info,
                            const struct oc_vpn_option **cstp_options,
index 2c35e0985b85d6366ec240613d27c6da3e65fb87..729d30148f26bd00bfda9198a5df87e8adf43607 100644 (file)
@@ -586,6 +586,7 @@ struct openconnect_info {
 
        struct oc_ip_info ip_info;
        int cstp_basemtu; /* Returned by server */
+       int idle_timeout; /* Returned by server */
 
 #ifdef _WIN32
        long dtls_monitored, ssl_monitored, cmd_monitored, tun_monitored;
index f8ea692021532d8c6c2a6da96971f8e1db376187..74a5124a637d3a7cc26292341520eddf998391ce 100644 (file)
@@ -40,6 +40,7 @@ extern "C" {
  *  - Add openconnect_get_supported_protocols()
  *  - Add openconnect_free_supported_protocols()
  *  - Add openconnect_get_protocol()
+ *  - Add openconnect_get_idle_timeout()
  *
  * API version 5.4 (v7.08; 2016-12-13):
  *  - Add openconnect_set_pass_tos()
@@ -514,6 +515,7 @@ int openconnect_set_client_cert(struct openconnect_info *, const char *cert,
 const char *openconnect_get_ifname(struct openconnect_info *);
 void openconnect_set_reqmtu(struct openconnect_info *, int reqmtu);
 void openconnect_set_dpd(struct openconnect_info *, int min_seconds);
+int openconnect_get_idle_timeout(struct openconnect_info *);
 
 /* The returned structures are owned by the library and may be freed/replaced
    due to rekey or reconnect. Assume that once the mainloop starts, the