diff options
author | Jukka Rissanen <jukka.rissanen@linux.intel.com> | 2012-04-05 12:00:44 +0300 |
---|---|---|
committer | Patrik Flykt <patrik.flykt@linux.intel.com> | 2012-04-05 14:17:08 +0300 |
commit | 4671d3fec969b8ec0d2de55aaad688661da4bf39 (patch) | |
tree | ebd47ed3965188c4bdfcab79002dbaf867e25aed | |
parent | 47b6a360bd00cebd9350815d8d0f52798c273f75 (diff) | |
download | connman-4671d3fec969b8ec0d2de55aaad688661da4bf39.tar.gz connman-4671d3fec969b8ec0d2de55aaad688661da4bf39.tar.bz2 connman-4671d3fec969b8ec0d2de55aaad688661da4bf39.zip |
provider: Add support for user defined routes
Allow user to add routes when setting up VPN. This is useful if
the VPN cannot be configured to setup additional routes itself.
-rw-r--r-- | src/connman.h | 2 | ||||
-rw-r--r-- | src/provider.c | 34 |
2 files changed, 36 insertions, 0 deletions
diff --git a/src/connman.h b/src/connman.h index 617ad328..556b9e1d 100644 --- a/src/connman.h +++ b/src/connman.h @@ -498,6 +498,8 @@ int __connman_private_network_release(const char *path); #include <connman/provider.h> +int __connman_provider_append_user_route(struct connman_provider *provider, + int family, const char *network, const char *netmask); void __connman_provider_append_properties(struct connman_provider *provider, DBusMessageIter *iter); void __connman_provider_list(DBusMessageIter *iter, void *user_data); int __connman_provider_create_and_connect(DBusMessage *msg); diff --git a/src/provider.c b/src/provider.c index a1e5391a..3183c3fb 100644 --- a/src/provider.c +++ b/src/provider.c @@ -58,6 +58,7 @@ struct connman_provider { struct connman_provider_driver *driver; void *driver_data; GHashTable *setting_strings; + GHashTable *user_routes; }; void __connman_provider_append_properties(struct connman_provider *provider, @@ -76,6 +77,33 @@ void __connman_provider_append_properties(struct connman_provider *provider, &provider->type); } +int __connman_provider_append_user_route(struct connman_provider *provider, + int family, const char *network, const char *netmask) +{ + struct connman_route *route; + char *key = g_strdup_printf("%d/%s/%s", family, network, netmask); + + DBG("family %d network %s netmask %s", family, network, netmask); + + route = g_hash_table_lookup(provider->user_routes, key); + if (route == NULL) { + route = g_try_new0(struct connman_route, 1); + if (route == NULL) { + connman_error("out of memory"); + return -ENOMEM; + } + + route->family = family; + route->host = g_strdup(network); + route->netmask = g_strdup(netmask); + + g_hash_table_replace(provider->user_routes, key, route); + } else + g_free(key); + + return 0; +} + static int provider_load_from_keyfile(struct connman_provider *provider, GKeyFile *keyfile) { @@ -238,6 +266,7 @@ static void provider_destruct(struct connman_provider *provider) g_free(provider->domain); g_free(provider->identifier); g_hash_table_destroy(provider->routes); + g_hash_table_destroy(provider->user_routes); g_hash_table_destroy(provider->setting_strings); g_free(provider); } @@ -395,6 +424,9 @@ static int set_connected(struct connman_provider *provider, g_hash_table_foreach(provider->routes, provider_append_routes, provider); + g_hash_table_foreach(provider->user_routes, provider_append_routes, + provider); + } else { if (ipconfig != NULL) { provider_indicate_state(provider, @@ -495,6 +527,8 @@ static void provider_initialize(struct connman_provider *provider) provider->identifier = NULL; provider->routes = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, destroy_route); + provider->user_routes = g_hash_table_new_full(g_str_hash, g_str_equal, + g_free, destroy_route); provider->setting_strings = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); } |