Commit 37fbeedd authored by Daniel Lenski's avatar Daniel Lenski

add protocol-agnostic idle_timeout and openconnect_get_idle_timeout() API function

This is needed for the Android GUI to detect the idle/keepalive interval in a cross-protocol way.
parent 7b551449
......@@ -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))
......
......@@ -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;
......
......@@ -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)
......
......@@ -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>();
......
......@@ -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 \
......
......@@ -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;
......
......@@ -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,
......
......@@ -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;
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment