provider: Implement IPv6 route setting
authorSamuel Ortiz <sameo@linux.intel.com>
Wed, 26 Jan 2011 16:03:12 +0000 (17:03 +0100)
committerSamuel Ortiz <sameo@linux.intel.com>
Wed, 26 Jan 2011 16:03:12 +0000 (17:03 +0100)
include/provider.h
plugins/openvpn.c
src/provider.c

index 569d47f..085bda3 100644 (file)
@@ -84,7 +84,8 @@ void connman_provider_set_domain(struct connman_provider *provider,
                                                        const char *domain);
 
 int connman_provider_append_route(struct connman_provider *provider,
-                                       const char *host, const char *netmask,
+                                       int family, const char *host,
+                                       const char *netmask,
                                        const char *gateway);
 
 const char *connman_provider_get_driver_name(struct connman_provider *provider);
index 24aa0bc..410cfbd 100644 (file)
@@ -43,6 +43,7 @@
 static DBusConnection *connection;
 
 struct ov_route {
+       int family;
        char *host;
        char *netmask;
        char *gateway;
@@ -64,8 +65,8 @@ static void ov_provider_append_routes(gpointer key, gpointer value,
        struct ov_route *route = value;
        struct connman_provider *provider = user_data;
 
-       connman_provider_append_route(provider, route->host, route->netmask,
-                                       route->gateway);
+       connman_provider_append_route(provider, route->family, route->host,
+                                       route->netmask, route->gateway);
 }
 
 static struct ov_route *ov_route_lookup(const char *key, const char *prefix_key,
@@ -95,6 +96,8 @@ static struct ov_route *ov_route_lookup(const char *key, const char *prefix_key,
                        return NULL;
                }
 
+               route->family = AF_INET;
+
                g_hash_table_replace(routes, GINT_TO_POINTER(idx),
                                                route);
        }
index b47b6b9..f7a512c 100644 (file)
@@ -25,6 +25,7 @@
 
 #include <stdio.h>
 #include <string.h>
+#include <stdlib.h>
 #include <gdbus.h>
 
 #include "connman.h"
@@ -36,6 +37,7 @@ static GHashTable *provider_hash = NULL;
 static GSList *driver_list = NULL;
 
 struct connman_route {
+       int family;
        char *host;
        char *netmask;
        char *gateway;
@@ -331,12 +333,21 @@ static int set_connected(struct connman_provider *provider,
 
                for (list = provider->route_list; list; list = list->next) {
                        struct connman_route *route = list->data;
+                       int index = provider->element.index;
 
-                       connman_inet_add_network_route(provider->element.index,
+                       if (route->family == AF_INET6) {
+                               unsigned char prefix_len = atoi(route->netmask);
+
+                               connman_inet_add_ipv6_network_route(index,
+                                                               route->host,
+                                                               route->gateway,
+                                                               prefix_len);
+                       } else {
+                               connman_inet_add_network_route(index,
                                                        route->host,
                                                        route->gateway,
                                                        route->netmask);
-                       /* XXX Need to handle IPv6 too */
+                       }
                }
        } else {
                connman_element_unregister_children(&provider->element);
@@ -747,15 +758,20 @@ int connman_provider_get_index(struct connman_provider *provider)
 }
 
 int connman_provider_append_route(struct connman_provider *provider,
-                                       const char *host, const char *netmask,
+                                       int family, const char *host,
+                                       const char *netmask,
                                        const char *gateway)
 {
        struct connman_route *route;
 
+       if (family != AF_INET && family != AF_INET6)
+               return -EINVAL;
+
        route = g_try_new0(struct connman_route, 1);
        if (route == NULL)
                return -ENOMEM;
 
+       route->family = family;
        route->host = g_strdup(host);
        route->netmask = g_strdup(netmask);
        route->gateway = g_strdup(gateway);