Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dlenski committed Aug 6, 2018
1 parent 7b55144 commit 37fbeed
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cstp.c
Expand Up @@ -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))
Expand Down
5 changes: 5 additions & 0 deletions gpst.c
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions java/src/com/example/LibTest.java
Expand Up @@ -275,6 +275,8 @@ else if (ret > 0)
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)
Expand Down
2 changes: 2 additions & 0 deletions java/src/org/infradead/libopenconnect/LibOpenConnect.java
Expand Up @@ -157,6 +157,7 @@ public synchronized native void setMobileInfo(String mobilePlatformVersion,
public synchronized native String getCSTPCompression();
public synchronized native String getDTLSCompression();
public synchronized native String getProtocol();
public synchronized native int getIdleTimeout();

/* certificate info */

Expand Down Expand Up @@ -247,6 +248,7 @@ public static class IPInfo {
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>();
Expand Down
10 changes: 10 additions & 0 deletions jni.c
Expand Up @@ -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 \
Expand Down
1 change: 1 addition & 0 deletions libopenconnect.map.in
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions library.c
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions openconnect-internal.h
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions openconnect.h
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 37fbeed

Please sign in to comment.