android: Repurpose android-net to simply handle connectivity events
authorTobias Brunner <tobias@strongswan.org>
Tue, 16 Apr 2013 12:40:19 +0000 (14:40 +0200)
committerTobias Brunner <tobias@strongswan.org>
Fri, 3 May 2013 13:11:20 +0000 (15:11 +0200)
Using the events by NetworkManager/ConnectivityManager to trigger roam events
instead of the events generated by the kernel-netlink plugin the noise level
is much lower.

src/frontends/android/jni/libandroidbridge/charonservice.c
src/frontends/android/jni/libandroidbridge/kernel/android_net.c
src/frontends/android/jni/libandroidbridge/kernel/android_net.h

index 4b2e58b..9afedf6 100644 (file)
@@ -1,7 +1,7 @@
 /*
+ * Copyright (C) 2012-2013 Tobias Brunner
  * Copyright (C) 2012 Giuliano Grassi
  * Copyright (C) 2012 Ralf Sager
- * Copyright (C) 2012 Tobias Brunner
  * Hochschule fuer Technik Rapperswil
  *
  * This program is free software; you can redistribute it and/or modify it
@@ -79,6 +79,11 @@ struct private_charonservice_t {
        network_manager_t *network_manager;
 
        /**
+        * Handle network events
+        */
+       android_net_t *net_handler;
+
+       /**
         * CharonVpnService reference
         */
        jobject vpn_service;
@@ -358,12 +363,14 @@ static bool charonservice_register(void *plugin, plugin_feature_t *feature,
        private_charonservice_t *this = (private_charonservice_t*)charonservice;
        if (reg)
        {
+               this->net_handler = android_net_create();
                lib->credmgr->add_set(lib->credmgr, &this->creds->set);
                hydra->attributes->add_handler(hydra->attributes,
                                                                           &this->attr->handler);
        }
        else
        {
+               this->net_handler->destroy(this->net_handler);
                lib->credmgr->remove_set(lib->credmgr, &this->creds->set);
                hydra->attributes->remove_handler(hydra->attributes,
                                                                                  &this->attr->handler);
@@ -413,6 +420,10 @@ static void set_options(char *logfile)
        /* don't install virtual IPs via kernel-netlink */
        lib->settings->set_bool(lib->settings,
                                        "charon.install_virtual_ip", FALSE);
+       /* kernel-netlink should not trigger roam events, we use Android's
+        * ConnectivityManager for that, much less noise */
+       lib->settings->set_bool(lib->settings,
+                                       "charon.plugins.kernel-netlink.roam_events", FALSE);
        /* ignore tun devices (it's mostly tun0 but it may already be taken, ignore
         * some others too) */
        lib->settings->set_str(lib->settings,
index 4b42b55..653e273 100644 (file)
 
 #include "../charonservice.h"
 #include <hydra.h>
-#include <utils/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;
+typedef struct private_android_net_t private_android_net_t;
 
-struct private_kernel_android_net_t {
+struct private_android_net_t {
 
        /**
         * Public kernel interface
         */
-       kernel_android_net_t public;
+       android_net_t public;
 
        /**
         * Reference to NetworkManager object
@@ -62,7 +61,7 @@ static job_requeue_t roam_event()
 /**
  * Listen for connectivity change events and queue a roam event
  */
-static void connectivity_cb(private_kernel_android_net_t *this,
+static void connectivity_cb(private_android_net_t *this,
                                                        bool disconnected)
 {
        timeval_t now;
@@ -84,30 +83,8 @@ static void connectivity_cb(private_kernel_android_net_t *this,
        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, get_interface, bool,
-       private_kernel_android_net_t *this, host_t *host, char **name)
-{
-       return this->network_manager->get_interface(this->network_manager, host,
-                                                                                               name);
-}
-
-METHOD(kernel_net_t, add_ip, status_t,
-       private_kernel_android_net_t *this, host_t *virtual_ip, int prefix,
-       char *iface)
-{
-       /* we get the IP from the IKE_SA once the CHILD_SA is established */
-       return SUCCESS;
-}
-
-METHOD(kernel_net_t, destroy, void,
-       private_kernel_android_net_t *this)
+METHOD(android_net_t, destroy, void,
+       private_android_net_t *this)
 {
        this->network_manager->remove_connectivity_cb(this->network_manager,
                                                                                                 (void*)connectivity_cb);
@@ -118,23 +95,13 @@ METHOD(kernel_net_t, destroy, void,
 /*
  * Described in header.
  */
-kernel_android_net_t *kernel_android_net_create()
+android_net_t *android_net_create()
 {
-       private_kernel_android_net_t *this;
+       private_android_net_t *this;
 
        INIT(this,
                .public = {
-                       .interface = {
-                               .get_source_addr = _get_source_addr,
-                               .get_nexthop = (void*)return_null,
-                               .get_interface = _get_interface,
-                               .create_address_enumerator = (void*)enumerator_create_empty,
-                               .add_ip = _add_ip,
-                               .del_ip = (void*)return_failed,
-                               .add_route = (void*)return_failed,
-                               .del_route = (void*)return_failed,
-                               .destroy = _destroy,
-                       },
+                       .destroy = _destroy,
                },
                .mutex = mutex_create(MUTEX_TYPE_DEFAULT),
                .network_manager = charonservice->get_network_manager(charonservice),
index f060539..ade83f3 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012 Tobias Brunner
+ * Copyright (C) 2012-2013 Tobias Brunner
  * Hochschule fuer Technik Rapperswil
  *
  * This program is free software; you can redistribute it and/or modify it
  */
 
 /**
- * @defgroup kernel_android_net kernel_android_net
+ * @defgroup android_net android_net
  * @{ @ingroup android_kernel
  */
 
-#ifndef KERNEL_ANDROID_NET_H_
-#define KERNEL_ANDROID_NET_H_
+#ifndef ANDROID_NET_H_
+#define ANDROID_NET_H_
 
 #include <library.h>
-#include <kernel/kernel_net.h>
 
-typedef struct kernel_android_net_t kernel_android_net_t;
+typedef struct android_net_t android_net_t;
 
 /**
- * Implementation of the kernel-net interface.  This currently consists of only
- * noops because a kernel_net_t implementation is required and we can't use
- * kernel_netlink_net_t at the moment.
+ * Handle connectivity events from NetworkManager
  */
-struct kernel_android_net_t {
+struct android_net_t {
 
        /**
-        * Implements kernel_net_t interface
+        * Destroy an android_net_t instance.
         */
-       kernel_net_t interface;
+       void (*destroy)(android_net_t *this);
 };
 
 /**
- * Create a android net interface instance.
+ * Create an android_net_t instance.
  *
- * @return                     kernel_android_net_t instance
+ * @return                     android_net_t instance
  */
-kernel_android_net_t *kernel_android_net_create();
+android_net_t *android_net_create();
 
-#endif /** KERNEL_ANDROID_NET_H_ @}*/
+#endif /** ANDROID_NET_H_ @}*/