From: Daniel Wagner <[email protected]>

---
 plugins/openvpn.c |   82 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 82 insertions(+), 0 deletions(-)

diff --git a/plugins/openvpn.c b/plugins/openvpn.c
index 0a71f5d..9f8989d 100644
--- a/plugins/openvpn.c
+++ b/plugins/openvpn.c
@@ -42,12 +42,74 @@
 
 static DBusConnection *connection;
 
+struct ov_route {
+       char *host;
+       char *netmask;
+       char *gateway;
+};
+
+static void destroy_route(gpointer user_data)
+{
+       struct ov_route *route = user_data;
+
+       g_free(route->host);
+       g_free(route->netmask);
+       g_free(route->gateway);
+       g_free(route);
+}
+
+static void ov_provider_append_routes(gpointer key, gpointer value,
+                                       gpointer user_data)
+{
+       struct ov_route *route = value;
+       struct connman_provider *provider = user_data;
+
+       connman_provider_append_route(provider, route->host, route->netmask,
+                                       route->gateway);
+}
+
+static struct ov_route *ov_route_lookup(const char *key, const char 
*prefix_key,
+                                       GHashTable *routes)
+{
+       if (g_str_has_prefix(key, prefix_key)) {
+               unsigned long idx;
+               const char *start;
+               char *end;
+               struct ov_route *route;
+
+               start = key + strlen(prefix_key);
+               idx = g_ascii_strtoull(start, &end, 10);
+
+               if (idx == 0 && start == end) {
+                       connman_error("string conversion failed %s", start);
+                       return NULL;
+               }
+
+               route = g_hash_table_lookup(routes, GINT_TO_POINTER(idx));
+               if (route == NULL) {
+                       route = g_try_new0(struct ov_route, 1);
+                       if (route == NULL) {
+                               connman_error("out of memory");
+                               return NULL;
+                       }
+
+                       g_hash_table_replace(routes, GINT_TO_POINTER(idx),
+                                               route);
+               }
+
+               return  route;
+       }
+
+       return NULL;
+}
+
 static int ov_notify(DBusMessage *msg, struct connman_provider *provider)
 {
        DBusMessageIter iter, dict;
        const char *reason, *key, *value;
        const char *domain = NULL;
        char *dns_entries = NULL;
+       GHashTable *routes;
 
        dbus_message_iter_init(msg, &iter);
 
@@ -71,8 +133,12 @@ static int ov_notify(DBusMessage *msg, struct 
connman_provider *provider)
 
        dbus_message_iter_recurse(&iter, &dict);
 
+       routes = g_hash_table_new_full(g_direct_hash, g_direct_equal,
+                                       NULL, destroy_route);
+
        while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
                DBusMessageIter entry;
+               struct ov_route *route;
 
                dbus_message_iter_recurse(&dict, &entry);
                dbus_message_iter_get_basic(&entry, &key);
@@ -115,6 +181,18 @@ static int ov_notify(DBusMessage *msg, struct 
connman_provider *provider)
                        g_strfreev(options);
                }
 
+               route = ov_route_lookup(key, "route_network_", routes);
+               if (route != NULL)
+                       route->host = g_strdup(value);
+
+               route = ov_route_lookup(key, "route_netmask_", routes);
+               if (route != NULL)
+                       route->netmask = g_strdup(value);
+
+               route = ov_route_lookup(key, "route_gateway_", routes);
+               if (route != NULL)
+                       route->gateway = g_strdup(value);
+
                dbus_message_iter_next(&dict);
        }
 
@@ -123,6 +201,10 @@ static int ov_notify(DBusMessage *msg, struct 
connman_provider *provider)
                g_free(dns_entries);
        }
 
+       g_hash_table_foreach(routes, ov_provider_append_routes, provider);
+
+       g_hash_table_destroy(routes);
+
        return VPN_STATE_CONNECT;
 }
 
-- 
1.7.3.2

_______________________________________________
connman mailing list
[email protected]
http://lists.connman.net/listinfo/connman

Reply via email to