aboutsummaryrefslogtreecommitdiffstats
path: root/src/frontends/android/jni/libandroidbridge/kernel/android_net.c
diff options
context:
space:
mode:
authorTobias Brunner <tobias@strongswan.org>2012-10-18 12:28:14 +0200
committerTobias Brunner <tobias@strongswan.org>2012-10-18 12:28:14 +0200
commit8bd00205f4f3c0c57eaf49f4d281f52befa9a855 (patch)
treecf6ac06017a3d99ee3f93420072d9902922ff5cf /src/frontends/android/jni/libandroidbridge/kernel/android_net.c
parentbbf90fcc79ce5de807136263713fcf48033a3bc7 (diff)
parent25a413cb96f9711411dd1590d62d323098c267e0 (diff)
downloadstrongswan-8bd00205f4f3c0c57eaf49f4d281f52befa9a855.tar.bz2
strongswan-8bd00205f4f3c0c57eaf49f4d281f52befa9a855.tar.xz
Merge branch 'android-mobility'
This brings support for MOBIKE to the Android app. The app also tries to keep the connection up as long as possible. DNS queries are now handled by a new class that uses independent threads to resolve them, this allows to cancel them e.g. if no network connectivity is available (otherwise the app would block until the DNS query returns).
Diffstat (limited to 'src/frontends/android/jni/libandroidbridge/kernel/android_net.c')
-rw-r--r--src/frontends/android/jni/libandroidbridge/kernel/android_net.c77
1 files changed, 76 insertions, 1 deletions
diff --git a/src/frontends/android/jni/libandroidbridge/kernel/android_net.c b/src/frontends/android/jni/libandroidbridge/kernel/android_net.c
index e29f95510..430c95bc8 100644
--- a/src/frontends/android/jni/libandroidbridge/kernel/android_net.c
+++ b/src/frontends/android/jni/libandroidbridge/kernel/android_net.c
@@ -14,6 +14,15 @@
#include "android_net.h"
+#include "../charonservice.h"
+#include <hydra.h>
+#include <debug.h>
+#include <processing/jobs/callback_job.h>
+#include <threading/mutex.h>
+
+/** delay before firing roam events (ms) */
+#define ROAM_DELAY 100
+
typedef struct private_kernel_android_net_t private_kernel_android_net_t;
struct private_kernel_android_net_t {
@@ -22,8 +31,66 @@ struct private_kernel_android_net_t {
* Public kernel interface
*/
kernel_android_net_t public;
+
+ /**
+ * Reference to NetworkManager object
+ */
+ network_manager_t *network_manager;
+
+ /**
+ * earliest time of the next roam event
+ */
+ timeval_t next_roam;
+
+ /**
+ * mutex to check and update roam event time
+ */
+ mutex_t *mutex;
};
+/**
+ * callback function that raises the delayed roam event
+ */
+static job_requeue_t roam_event()
+{
+ /* this will fail if no connection is up */
+ charonservice->bypass_socket(charonservice, -1, 0);
+ hydra->kernel_interface->roam(hydra->kernel_interface, TRUE);
+ return JOB_REQUEUE_NONE;
+}
+
+/**
+ * Listen for connectivity change events and queue a roam event
+ */
+static void connectivity_cb(private_kernel_android_net_t *this,
+ bool disconnected)
+{
+ timeval_t now;
+ job_t *job;
+
+ time_monotonic(&now);
+ this->mutex->lock(this->mutex);
+ if (!timercmp(&now, &this->next_roam, >))
+ {
+ this->mutex->unlock(this->mutex);
+ return;
+ }
+ timeval_add_ms(&now, ROAM_DELAY);
+ this->next_roam = now;
+ this->mutex->unlock(this->mutex);
+
+ job = (job_t*)callback_job_create((callback_job_cb_t)roam_event, NULL,
+ NULL, NULL);
+ lib->scheduler->schedule_job_ms(lib->scheduler, job, ROAM_DELAY);
+}
+
+METHOD(kernel_net_t, get_source_addr, host_t*,
+ private_kernel_android_net_t *this, host_t *dest, host_t *src)
+{
+ return this->network_manager->get_local_address(this->network_manager,
+ dest->get_family(dest) == AF_INET);
+}
+
METHOD(kernel_net_t, add_ip, status_t,
private_kernel_android_net_t *this, host_t *virtual_ip, host_t *iface_ip)
{
@@ -34,6 +101,9 @@ METHOD(kernel_net_t, add_ip, status_t,
METHOD(kernel_net_t, destroy, void,
private_kernel_android_net_t *this)
{
+ this->network_manager->remove_connectivity_cb(this->network_manager,
+ (void*)connectivity_cb);
+ this->mutex->destroy(this->mutex);
free(this);
}
@@ -47,7 +117,7 @@ kernel_android_net_t *kernel_android_net_create()
INIT(this,
.public = {
.interface = {
- .get_source_addr = (void*)return_null,
+ .get_source_addr = _get_source_addr,
.get_nexthop = (void*)return_null,
.get_interface = (void*)return_null,
.create_address_enumerator = (void*)enumerator_create_empty,
@@ -58,7 +128,12 @@ kernel_android_net_t *kernel_android_net_create()
.destroy = _destroy,
},
},
+ .mutex = mutex_create(MUTEX_TYPE_DEFAULT),
+ .network_manager = charonservice->get_network_manager(charonservice),
);
+ timerclear(&this->next_roam);
+ this->network_manager->add_connectivity_cb(this->network_manager,
+ (void*)connectivity_cb, this);
return &this->public;
};