5 * Copyright (C) 2012-2013 Intel Corporation. All rights reserved.
6 * Copyright (C) 2019 Jolla Ltd. All rights reserved.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
32 #include <connman/log.h>
33 #include <gweb/gresolv.h>
36 #include "../src/connman.h"
37 #include "connman/agent.h"
38 #include "connman/vpn-dbus.h"
39 #include "vpn-provider.h"
41 #include "plugins/vpn.h"
43 static DBusConnection *connection;
44 static GHashTable *provider_hash;
45 static GSList *driver_list;
46 static int configuration_count;
47 static bool handle_routes;
66 enum vpn_provider_state state;
75 struct vpn_provider_driver *driver;
77 GHashTable *setting_strings;
78 GHashTable *user_routes;
79 GSList *user_networks;
82 struct vpn_ipconfig *ipconfig_ipv4;
83 struct vpn_ipconfig *ipconfig_ipv6;
89 struct connman_ipaddress *prev_ipv4_addr;
90 struct connman_ipaddress *prev_ipv6_addr;
92 unsigned int auth_error_counter;
93 unsigned int conn_error_counter;
96 static void append_properties(DBusMessageIter *iter,
97 struct vpn_provider *provider);
98 static int vpn_provider_save(struct vpn_provider *provider);
100 static void free_route(gpointer data)
102 struct vpn_route *route = data;
104 g_free(route->network);
105 g_free(route->netmask);
106 g_free(route->gateway);
111 static void free_setting(gpointer data)
113 struct vpn_setting *setting = data;
115 g_free(setting->value);
119 static void append_route(DBusMessageIter *iter, void *user_data)
121 struct vpn_route *route = user_data;
122 DBusMessageIter item;
125 connman_dbus_dict_open(iter, &item);
130 if (route->family == AF_INET)
132 else if (route->family == AF_INET6)
136 connman_dbus_dict_append_basic(&item, "ProtocolFamily",
137 DBUS_TYPE_INT32, &family);
140 connman_dbus_dict_append_basic(&item, "Network",
141 DBUS_TYPE_STRING, &route->network);
144 connman_dbus_dict_append_basic(&item, "Netmask",
145 DBUS_TYPE_STRING, &route->netmask);
148 connman_dbus_dict_append_basic(&item, "Gateway",
149 DBUS_TYPE_STRING, &route->gateway);
152 connman_dbus_dict_close(iter, &item);
155 static void append_routes(DBusMessageIter *iter, void *user_data)
157 GHashTable *routes = user_data;
162 append_route(iter, NULL);
166 g_hash_table_iter_init(&hash, routes);
168 while (g_hash_table_iter_next(&hash, &key, &value)) {
169 DBusMessageIter dict;
171 dbus_message_iter_open_container(iter, DBUS_TYPE_STRUCT, NULL,
173 append_route(&dict, value);
174 dbus_message_iter_close_container(iter, &dict);
178 static void send_routes(struct vpn_provider *provider, GHashTable *routes,
181 connman_dbus_property_changed_array(provider->path,
182 VPN_CONNECTION_INTERFACE,
184 DBUS_TYPE_DICT_ENTRY,
189 static int provider_routes_changed(struct vpn_provider *provider)
191 DBG("provider %p", provider);
193 send_routes(provider, provider->routes, "ServerRoutes");
199 * Sort vpn_route struct based on (similarly to the route key in hash table):
200 * 1) IP protocol number
201 * 2) Network addresses
202 * 3) Netmask addresses
203 * 4) Gateway addresses
205 static gint compare_route(gconstpointer a, gconstpointer b)
207 const struct vpn_route *route_a = a;
208 const struct vpn_route *route_b = b;
211 /* If IP families differ, prefer IPv6 over IPv4 */
212 if (route_a->family != route_b->family) {
213 if (route_a->family < route_b->family)
216 if (route_a->family > route_b->family)
220 /* If networks differ, return */
221 if ((difference = g_strcmp0(route_a->network, route_b->network)))
224 /* If netmasks differ, return. */
225 if ((difference = g_strcmp0(route_a->netmask, route_b->netmask)))
228 return g_strcmp0(route_a->gateway, route_b->gateway);
231 static GSList *read_route_dict(GSList *routes, DBusMessageIter *dicts)
233 DBusMessageIter dict, value, entry;
234 const char *network, *netmask, *gateway;
235 struct vpn_route *route;
239 dbus_message_iter_recurse(dicts, &entry);
241 network = netmask = gateway = NULL;
244 while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_DICT_ENTRY) {
246 dbus_message_iter_recurse(&entry, &dict);
247 dbus_message_iter_get_basic(&dict, &key);
249 dbus_message_iter_next(&dict);
250 dbus_message_iter_recurse(&dict, &value);
252 type = dbus_message_iter_get_arg_type(&value);
255 case DBUS_TYPE_INT32:
256 if (g_str_equal(key, "ProtocolFamily"))
257 dbus_message_iter_get_basic(&value, &family);
260 case DBUS_TYPE_STRING:
261 if (g_str_equal(key, "Network"))
262 dbus_message_iter_get_basic(&value, &network);
263 else if (g_str_equal(key, "Netmask"))
264 dbus_message_iter_get_basic(&value, &netmask);
265 else if (g_str_equal(key, "Gateway"))
266 dbus_message_iter_get_basic(&value, &gateway);
270 dbus_message_iter_next(&entry);
273 DBG("family %d network %s netmask %s gateway %s", family,
274 network, netmask, gateway);
276 if (!network || !netmask) {
277 DBG("Ignoring route as network/netmask is missing");
281 route = g_try_new(struct vpn_route, 1);
283 g_slist_free_full(routes, free_route);
287 if (family == PF_UNSPEC) {
288 family = connman_inet_check_ipaddress(network);
290 DBG("Cannot get address family of %s (%d/%s)", network,
291 family, gai_strerror(family));
312 route->family = family;
313 route->network = g_strdup(network);
314 route->netmask = g_strdup(netmask);
315 route->gateway = g_strdup(gateway);
317 routes = g_slist_insert_sorted(routes, route, compare_route);
321 static GSList *get_user_networks(DBusMessageIter *array)
323 DBusMessageIter entry;
326 while (dbus_message_iter_get_arg_type(array) == DBUS_TYPE_ARRAY) {
328 dbus_message_iter_recurse(array, &entry);
330 while (dbus_message_iter_get_arg_type(&entry) ==
332 DBusMessageIter dicts;
334 dbus_message_iter_recurse(&entry, &dicts);
336 while (dbus_message_iter_get_arg_type(&dicts) ==
339 list = read_route_dict(list, &dicts);
340 dbus_message_iter_next(&dicts);
343 dbus_message_iter_next(&entry);
346 dbus_message_iter_next(array);
352 static void set_user_networks(struct vpn_provider *provider, GSList *networks)
356 for (list = networks; list; list = g_slist_next(list)) {
357 struct vpn_route *route = list->data;
359 if (__vpn_provider_append_user_route(provider,
360 route->family, route->network,
361 route->netmask, route->gateway) != 0)
366 static void del_routes(struct vpn_provider *provider)
371 g_hash_table_iter_init(&hash, provider->user_routes);
372 while (handle_routes && g_hash_table_iter_next(&hash,
374 struct vpn_route *route = value;
375 if (route->family == AF_INET6) {
376 unsigned char prefixlen = atoi(route->netmask);
377 connman_inet_del_ipv6_network_route(provider->index,
381 connman_inet_del_host_route(provider->index,
385 g_hash_table_remove_all(provider->user_routes);
386 g_slist_free_full(provider->user_networks, free_route);
387 provider->user_networks = NULL;
390 static void send_value(const char *path, const char *key, const char *value)
392 const char *empty = "";
400 connman_dbus_property_changed_basic(path,
401 VPN_CONNECTION_INTERFACE,
407 static gboolean provider_send_changed(gpointer data)
409 struct vpn_provider *provider = data;
411 provider_routes_changed(provider);
413 provider->notify_id = 0;
418 static void provider_schedule_changed(struct vpn_provider *provider)
420 if (provider->notify_id != 0)
421 g_source_remove(provider->notify_id);
423 provider->notify_id = g_timeout_add(100, provider_send_changed,
427 static DBusMessage *get_properties(DBusConnection *conn,
428 DBusMessage *msg, void *data)
430 struct vpn_provider *provider = data;
432 DBusMessageIter array;
434 DBG("provider %p", provider);
436 reply = dbus_message_new_method_return(msg);
440 dbus_message_iter_init_append(reply, &array);
442 append_properties(&array, provider);
447 /* True when lists are equal, false otherwise */
448 static bool compare_network_lists(GSList *a, GSList *b)
450 struct vpn_route *route_a, *route_b;
451 GSList *iter_a, *iter_b;
457 * If either of lists is NULL or the lists are of different size, the
458 * lists are not equal.
460 if ((!a || !b) || (g_slist_length(a) != g_slist_length(b)))
463 /* Routes are in sorted list so items can be compared in order. */
464 for (iter_a = a, iter_b = b; iter_a && iter_b;
465 iter_a = iter_a->next, iter_b = iter_b->next) {
467 route_a = iter_a->data;
468 route_b = iter_b->data;
470 if (compare_route(route_a, route_b))
477 static int set_provider_property(struct vpn_provider *provider,
478 const char *name, DBusMessageIter *value, int type)
482 DBG("provider %p", provider);
484 if (!provider || !name || !value)
487 if (g_str_equal(name, "UserRoutes")) {
490 if (type != DBUS_TYPE_ARRAY)
493 networks = get_user_networks(value);
495 if (compare_network_lists(provider->user_networks, networks)) {
496 g_slist_free_full(networks, free_route);
500 del_routes(provider);
501 provider->user_networks = networks;
502 set_user_networks(provider, provider->user_networks);
505 send_routes(provider, provider->user_routes,
510 if (type != DBUS_TYPE_STRING)
513 dbus_message_iter_get_basic(value, &str);
515 DBG("property %s value %s", name, str);
517 /* Empty string clears the value, similar to ClearProperty. */
518 err = vpn_provider_set_string(provider, name,
525 static GString *append_to_gstring(GString *str, const char *value)
528 return g_string_new(value);
530 g_string_append_printf(str, ",%s", value);
535 static DBusMessage *set_properties(DBusMessageIter *iter, DBusMessage *msg,
538 struct vpn_provider *provider = data;
539 DBusMessageIter dict;
542 GString *invalid = NULL;
543 GString *denied = NULL;
547 for (dbus_message_iter_recurse(iter, &dict);
548 dbus_message_iter_get_arg_type(&dict) ==
549 DBUS_TYPE_DICT_ENTRY;
550 dbus_message_iter_next(&dict)) {
551 DBusMessageIter entry, value;
553 dbus_message_iter_recurse(&dict, &entry);
555 * Ignore invalid types in order to process all values in the
556 * dict. If there is an invalid type in between the dict there
557 * may already be changes on some values and breaking out here
558 * would have the provider in an inconsistent state, leaving
559 * the rest, potentially correct property values untouched.
561 if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING)
564 dbus_message_iter_get_basic(&entry, &key);
568 dbus_message_iter_next(&entry);
569 /* Ignore and report back all non variant types. */
570 if (dbus_message_iter_get_arg_type(&entry)
571 != DBUS_TYPE_VARIANT) {
572 invalid = append_to_gstring(invalid, key);
576 dbus_message_iter_recurse(&entry, &value);
578 type = dbus_message_iter_get_arg_type(&value);
579 /* Ignore and report back all invalid property types */
580 if (type != DBUS_TYPE_STRING && type != DBUS_TYPE_ARRAY) {
581 invalid = append_to_gstring(invalid, key);
585 err = set_provider_property(provider, key, &value, type);
591 invalid = append_to_gstring(invalid, key);
594 denied = append_to_gstring(denied, key);
600 vpn_provider_save(provider);
602 if (invalid || denied) {
604 char *invalid_str = g_string_free(invalid, FALSE);
605 char *denied_str = g_string_free(denied, FALSE);
608 * If there are both invalid and denied properties report
609 * back invalid arguments. Add also the failed properties to
612 error = g_dbus_create_error(msg, (invalid ?
613 CONNMAN_ERROR_INTERFACE ".InvalidProperty" :
614 CONNMAN_ERROR_INTERFACE ".PermissionDenied"),
615 "%s %s%s%s", (invalid ? "Invalid properties" :
616 "Permission denied"),
617 (invalid ? invalid_str : ""),
618 (invalid && denied ? "," : ""),
619 (denied ? denied_str : ""));
627 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
630 static DBusMessage *set_property(DBusConnection *conn, DBusMessage *msg,
633 struct vpn_provider *provider = data;
634 DBusMessageIter iter, value;
639 DBG("conn %p", conn);
641 if (provider->immutable)
642 return __connman_error_not_supported(msg);
644 if (!dbus_message_iter_init(msg, &iter))
645 return __connman_error_invalid_arguments(msg);
647 if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
648 return __connman_error_invalid_arguments(msg);
650 dbus_message_iter_get_basic(&iter, &name);
651 dbus_message_iter_next(&iter);
653 if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT)
654 return __connman_error_invalid_arguments(msg);
656 dbus_message_iter_recurse(&iter, &value);
658 type = dbus_message_iter_get_arg_type(&value);
659 if (type == DBUS_TYPE_ARRAY && g_str_equal(name, "Properties"))
660 return set_properties(&value, msg, data);
662 err = set_provider_property(provider, name, &value, type);
665 vpn_provider_save(provider);
670 return __connman_error_invalid_property(msg);
672 return __connman_error_failed(msg, -err);
675 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
678 static DBusMessage *clear_property(DBusConnection *conn, DBusMessage *msg,
681 struct vpn_provider *provider = data;
686 DBG("conn %p", conn);
688 if (provider->immutable)
689 return __connman_error_not_supported(msg);
691 dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &name,
694 if (g_str_equal(name, "UserRoutes")) {
696 * If either user_routes or user_networks has any entries
697 * there is a change that is to be written to settings file.
699 if (g_hash_table_size(provider->user_routes) ||
700 provider->user_networks)
703 del_routes(provider);
706 send_routes(provider, provider->user_routes, name);
707 } else if (vpn_provider_get_string(provider, name)) {
708 err = vpn_provider_set_string(provider, name, NULL);
716 return __connman_error_invalid_property(msg);
718 return __connman_error_failed(msg, -err);
721 return __connman_error_invalid_property(msg);
725 vpn_provider_save(provider);
727 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
730 static DBusMessage *do_connect(DBusConnection *conn, DBusMessage *msg,
733 struct vpn_provider *provider = data;
736 DBG("conn %p provider %p", conn, provider);
738 err = __vpn_provider_connect(provider, msg);
739 if (err < 0 && err != -EINPROGRESS)
740 return __connman_error_failed(msg, -err);
745 static DBusMessage *do_connect2(DBusConnection *conn, DBusMessage *msg,
748 return do_connect(conn, msg, data);
751 static DBusMessage *do_disconnect(DBusConnection *conn, DBusMessage *msg,
754 struct vpn_provider *provider = data;
757 DBG("conn %p provider %p", conn, provider);
759 err = __vpn_provider_disconnect(provider);
760 if (err < 0 && err != -EINPROGRESS)
761 return __connman_error_failed(msg, -err);
763 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
766 static const GDBusMethodTable connection_methods[] = {
767 { GDBUS_METHOD("GetProperties",
768 NULL, GDBUS_ARGS({ "properties", "a{sv}" }),
770 { GDBUS_METHOD("SetProperty",
771 GDBUS_ARGS({ "name", "s" }, { "value", "v" }),
772 NULL, set_property) },
773 { GDBUS_METHOD("ClearProperty",
774 GDBUS_ARGS({ "name", "s" }), NULL,
776 { GDBUS_ASYNC_METHOD("Connect", NULL, NULL, do_connect) },
777 { GDBUS_ASYNC_METHOD("Connect2",
778 GDBUS_ARGS({ "dbus_sender", "s" }),
779 NULL, do_connect2) },
780 { GDBUS_METHOD("Disconnect", NULL, NULL, do_disconnect) },
784 static const GDBusSignalTable connection_signals[] = {
785 { GDBUS_SIGNAL("PropertyChanged",
786 GDBUS_ARGS({ "name", "s" }, { "value", "v" })) },
790 static void resolv_result(GResolvResultStatus status,
791 char **results, gpointer user_data)
793 struct vpn_provider *provider = user_data;
795 DBG("status %d", status);
797 if (status == G_RESOLV_RESULT_STATUS_SUCCESS && results &&
798 g_strv_length(results) > 0)
799 provider->host_ip = g_strdupv(results);
801 vpn_provider_unref(provider);
803 /* Remove the resolver here so that it will not be left
804 * hanging around and cause double free in unregister_provider()
806 g_resolv_unref(provider->resolv);
807 provider->resolv = NULL;
810 static void provider_resolv_host_addr(struct vpn_provider *provider)
815 if (connman_inet_check_ipaddress(provider->host) > 0)
818 if (provider->host_ip)
822 * If the hostname is not numeric, try to resolv it. We do not wait
823 * the result as it might take some time. We will get the result
824 * before VPN will feed routes to us because VPN client will need
825 * the IP address also before VPN connection can be established.
827 provider->resolv = g_resolv_new(0);
828 if (!provider->resolv) {
829 DBG("Cannot resolv %s", provider->host);
833 DBG("Trying to resolv %s", provider->host);
835 vpn_provider_ref(provider);
837 g_resolv_lookup_hostname(provider->resolv, provider->host,
838 resolv_result, provider);
841 void __vpn_provider_append_properties(struct vpn_provider *provider,
842 DBusMessageIter *iter)
845 connman_dbus_dict_append_basic(iter, "Host",
846 DBUS_TYPE_STRING, &provider->host);
848 if (provider->domain)
849 connman_dbus_dict_append_basic(iter, "Domain",
850 DBUS_TYPE_STRING, &provider->domain);
853 connman_dbus_dict_append_basic(iter, "Type", DBUS_TYPE_STRING,
857 int __vpn_provider_append_user_route(struct vpn_provider *provider,
858 int family, const char *network,
859 const char *netmask, const char *gateway)
861 struct vpn_route *route;
862 char *key = g_strdup_printf("%d/%s/%s/%s", family, network,
863 netmask, gateway ? gateway : "");
865 DBG("family %d network %s netmask %s gw %s", family, network,
868 route = g_hash_table_lookup(provider->user_routes, key);
870 route = g_try_new0(struct vpn_route, 1);
872 connman_error("out of memory");
876 route->family = family;
877 route->network = g_strdup(network);
878 route->netmask = g_strdup(netmask);
879 route->gateway = g_strdup(gateway);
881 g_hash_table_replace(provider->user_routes, key, route);
888 static struct vpn_route *get_route(char *route_str)
890 char **elems = g_strsplit(route_str, "/", 0);
891 char *network, *netmask, *gateway, *family_str;
892 int family = PF_UNSPEC;
893 struct vpn_route *route = NULL;
898 family_str = elems[0];
901 if (!network || network[0] == '\0')
905 if (!netmask || netmask[0] == '\0')
910 route = g_try_new0(struct vpn_route, 1);
914 if (family_str[0] == '\0' || atoi(family_str) == 0) {
917 switch (family_str[0]) {
927 if (g_strrstr(network, ":")) {
928 if (family != PF_UNSPEC && family != AF_INET6)
929 DBG("You have IPv6 address but you have non IPv6 route");
930 } else if (g_strrstr(network, ".")) {
931 if (family != PF_UNSPEC && family != AF_INET)
932 DBG("You have IPv4 address but you have non IPv4 route");
934 if (!g_strrstr(netmask, ".")) {
935 /* We have netmask length */
937 struct in_addr netmask_in;
938 unsigned char prefix_len = 32;
940 long int value = strtol(netmask, &ptr, 10);
942 if (ptr != netmask && *ptr == '\0' && value <= 32)
945 addr = 0xffffffff << (32 - prefix_len);
946 netmask_in.s_addr = htonl(addr);
947 netmask = inet_ntoa(netmask_in);
949 DBG("network %s netmask %s", network, netmask);
953 if (family == PF_UNSPEC) {
954 family = connman_inet_check_ipaddress(network);
955 if (family < 0 || family == PF_UNSPEC)
959 route->family = family;
960 route->network = g_strdup(network);
961 route->netmask = g_strdup(netmask);
962 route->gateway = g_strdup(gateway);
969 static GSList *get_routes(gchar **networks)
971 struct vpn_route *route;
972 GSList *routes = NULL;
975 for (i = 0; networks[i]; i++) {
976 route = get_route(networks[i]);
978 routes = g_slist_prepend(routes, route);
984 static int provider_load_from_keyfile(struct vpn_provider *provider,
990 gsize length, num_user_networks;
991 gchar **networks = NULL;
993 settings = g_key_file_get_keys(keyfile, provider->identifier, &length,
996 g_key_file_free(keyfile);
1000 while (idx < length) {
1001 key = settings[idx];
1003 if (g_str_equal(key, "Networks")) {
1004 networks = __vpn_config_get_string_list(keyfile,
1005 provider->identifier,
1009 provider->user_networks = get_routes(networks);
1012 value = __vpn_config_get_string(keyfile,
1013 provider->identifier,
1015 vpn_provider_set_string(provider, key,
1022 g_strfreev(settings);
1023 g_strfreev(networks);
1025 if (provider->user_networks)
1026 set_user_networks(provider, provider->user_networks);
1032 static int vpn_provider_load(struct vpn_provider *provider)
1036 DBG("provider %p", provider);
1038 keyfile = __connman_storage_load_provider(provider->identifier);
1042 provider_load_from_keyfile(provider, keyfile);
1044 g_key_file_free(keyfile);
1048 static gchar **create_network_list(GSList *networks, gsize *count)
1051 gchar **result = NULL;
1052 gchar **prev_result;
1053 unsigned int num_elems = 0;
1055 for (list = networks; list; list = g_slist_next(list)) {
1056 struct vpn_route *route = list->data;
1059 prev_result = result;
1060 result = g_try_realloc(result,
1061 (num_elems + 1) * sizeof(gchar *));
1063 g_free(prev_result);
1067 switch (route->family) {
1079 result[num_elems] = g_strdup_printf("%d/%s/%s/%s",
1080 family, route->network, route->netmask,
1081 !route->gateway ? "" : route->gateway);
1086 prev_result = result;
1087 result = g_try_realloc(result, (num_elems + 1) * sizeof(gchar *));
1089 g_free(prev_result);
1093 result[num_elems] = NULL;
1098 static void reset_error_counters(struct vpn_provider *provider)
1103 provider->auth_error_counter = provider->conn_error_counter = 0;
1106 static int vpn_provider_save(struct vpn_provider *provider)
1110 DBG("provider %p immutable %s", provider,
1111 provider->immutable ? "yes" : "no");
1113 reset_error_counters(provider);
1115 if (provider->state == VPN_PROVIDER_STATE_FAILURE)
1116 vpn_provider_set_state(provider, VPN_PROVIDER_STATE_IDLE);
1118 if (provider->immutable) {
1120 * Do not save providers that are provisioned via .config
1126 keyfile = g_key_file_new();
1130 g_key_file_set_string(keyfile, provider->identifier,
1131 "Name", provider->name);
1132 g_key_file_set_string(keyfile, provider->identifier,
1133 "Type", provider->type);
1134 g_key_file_set_string(keyfile, provider->identifier,
1135 "Host", provider->host);
1136 g_key_file_set_string(keyfile, provider->identifier,
1137 "VPN.Domain", provider->domain);
1138 if (provider->user_networks) {
1140 gsize network_count;
1142 networks = create_network_list(provider->user_networks,
1145 g_key_file_set_string_list(keyfile,
1146 provider->identifier,
1148 (const gchar ** const)networks,
1150 g_strfreev(networks);
1154 if (provider->config_file && strlen(provider->config_file) > 0)
1155 g_key_file_set_string(keyfile, provider->identifier,
1156 "Config.file", provider->config_file);
1158 if (provider->config_entry &&
1159 strlen(provider->config_entry) > 0)
1160 g_key_file_set_string(keyfile, provider->identifier,
1161 "Config.ident", provider->config_entry);
1163 if (provider->driver && provider->driver->save)
1164 provider->driver->save(provider, keyfile);
1166 __connman_storage_save_provider(keyfile, provider->identifier);
1167 g_key_file_free(keyfile);
1172 struct vpn_provider *__vpn_provider_lookup(const char *identifier)
1174 struct vpn_provider *provider = NULL;
1176 provider = g_hash_table_lookup(provider_hash, identifier);
1181 static bool match_driver(struct vpn_provider *provider,
1182 struct vpn_provider_driver *driver)
1184 if (g_strcmp0(driver->name, provider->type) == 0)
1190 static int provider_probe(struct vpn_provider *provider)
1194 DBG("provider %p driver %p name %s", provider, provider->driver,
1197 if (provider->driver)
1200 for (list = driver_list; list; list = list->next) {
1201 struct vpn_provider_driver *driver = list->data;
1203 if (!match_driver(provider, driver))
1206 DBG("driver %p name %s", driver, driver->name);
1208 if (driver->probe && driver->probe(provider) == 0) {
1209 provider->driver = driver;
1214 if (!provider->driver)
1220 static void provider_remove(struct vpn_provider *provider)
1222 if (provider->driver) {
1223 provider->driver->remove(provider);
1224 provider->driver = NULL;
1228 static int provider_register(struct vpn_provider *provider)
1230 return provider_probe(provider);
1233 static void provider_unregister(struct vpn_provider *provider)
1235 provider_remove(provider);
1238 struct vpn_provider *
1239 vpn_provider_ref_debug(struct vpn_provider *provider,
1240 const char *file, int line, const char *caller)
1242 DBG("%p ref %d by %s:%d:%s()", provider, provider->refcount + 1,
1243 file, line, caller);
1245 __sync_fetch_and_add(&provider->refcount, 1);
1250 static void provider_destruct(struct vpn_provider *provider)
1252 DBG("provider %p", provider);
1254 if (provider->notify_id != 0)
1255 g_source_remove(provider->notify_id);
1257 g_free(provider->name);
1258 g_free(provider->type);
1259 g_free(provider->host);
1260 g_free(provider->domain);
1261 g_free(provider->identifier);
1262 g_free(provider->path);
1263 g_slist_free_full(provider->user_networks, free_route);
1264 g_strfreev(provider->nameservers);
1265 g_hash_table_destroy(provider->routes);
1266 g_hash_table_destroy(provider->user_routes);
1267 g_hash_table_destroy(provider->setting_strings);
1268 if (provider->resolv) {
1269 g_resolv_unref(provider->resolv);
1270 provider->resolv = NULL;
1272 __vpn_ipconfig_unref(provider->ipconfig_ipv4);
1273 __vpn_ipconfig_unref(provider->ipconfig_ipv6);
1275 g_strfreev(provider->host_ip);
1276 g_free(provider->config_file);
1277 g_free(provider->config_entry);
1278 connman_ipaddress_free(provider->prev_ipv4_addr);
1279 connman_ipaddress_free(provider->prev_ipv6_addr);
1283 void vpn_provider_unref_debug(struct vpn_provider *provider,
1284 const char *file, int line, const char *caller)
1286 DBG("%p ref %d by %s:%d:%s()", provider, provider->refcount - 1,
1287 file, line, caller);
1289 if (__sync_fetch_and_sub(&provider->refcount, 1) != 1)
1292 provider_remove(provider);
1294 provider_destruct(provider);
1297 static void configuration_count_add(void)
1299 DBG("count %d", configuration_count + 1);
1301 __sync_fetch_and_add(&configuration_count, 1);
1304 static void configuration_count_del(void)
1306 DBG("count %d", configuration_count - 1);
1308 if (__sync_fetch_and_sub(&configuration_count, 1) != 1)
1312 int __vpn_provider_disconnect(struct vpn_provider *provider)
1316 DBG("provider %p", provider);
1318 if (provider->driver && provider->driver->disconnect)
1319 err = provider->driver->disconnect(provider);
1323 if (err == -EINPROGRESS)
1324 vpn_provider_set_state(provider, VPN_PROVIDER_STATE_CONNECT);
1329 static void connect_cb(struct vpn_provider *provider, void *user_data,
1332 DBusMessage *pending = user_data;
1334 DBG("provider %p user %p error %d", provider, user_data, error);
1337 DBusMessage *reply = __connman_error_failed(pending, error);
1339 g_dbus_send_message(connection, reply);
1343 vpn_provider_indicate_error(provider,
1344 VPN_PROVIDER_ERROR_AUTH_FAILED);
1348 * No reply, disconnect called by connmand because of
1349 * connection timeout.
1355 /* No reply or timed out -> cancel the agent request */
1356 connman_agent_cancel(provider);
1357 vpn_provider_indicate_error(provider,
1358 VPN_PROVIDER_ERROR_UNKNOWN);
1364 * This can be called in other situations than when
1365 * VPN agent error checker is called. In such case
1366 * react to both ECONNABORTED and ECANCELED as if the
1367 * connection was called to terminate and do full
1368 * disconnect -> idle cycle when being connected or
1369 * ready. Setting the state also using the driver
1370 * callback (vpn_set_state()) ensures that the driver is
1371 * being disconnected as well and eventually the vpn
1372 * process gets killed and vpn_died() is called to make
1373 * the provider back to idle state.
1375 if (provider->state == VPN_PROVIDER_STATE_CONNECT ||
1377 VPN_PROVIDER_STATE_READY) {
1378 if (provider->driver->set_state)
1379 provider->driver->set_state(provider,
1380 VPN_PROVIDER_STATE_DISCONNECT);
1382 vpn_provider_set_state(provider,
1383 VPN_PROVIDER_STATE_DISCONNECT);
1387 vpn_provider_indicate_error(provider,
1388 VPN_PROVIDER_ERROR_CONNECT_FAILED);
1389 vpn_provider_set_state(provider,
1390 VPN_PROVIDER_STATE_FAILURE);
1393 reset_error_counters(provider);
1394 g_dbus_send_reply(connection, pending, DBUS_TYPE_INVALID);
1397 dbus_message_unref(pending);
1400 int __vpn_provider_connect(struct vpn_provider *provider, DBusMessage *msg)
1405 DBG("provider %p state %d", provider, provider->state);
1407 switch (provider->state) {
1409 * When previous connection has failed change state to idle and let
1410 * the connmand to process this information as well. Return -EINPROGRESS
1411 * to indicate that transition is in progress and next connection
1412 * attempt will continue as normal.
1414 case VPN_PROVIDER_STATE_FAILURE:
1415 if (provider->driver && provider->driver->set_state)
1416 provider->driver->set_state(provider,
1417 VPN_PROVIDER_STATE_IDLE);
1419 vpn_provider_set_state(provider, VPN_PROVIDER_STATE_IDLE);
1422 * If re-using a provider and it is being disconnected let it finish
1423 * the disconnect process in order to let vpn.c:vpn_died() to get
1424 * processed and everything cleaned up. Otherwise the reference
1425 * counters are not decreased properly causing the previous interface
1426 * being left up and its routes will remain in routing table. Return
1427 * -EINPROGRESS to indicate that transition is in progress.
1429 case VPN_PROVIDER_STATE_DISCONNECT:
1431 * Failure transition or disconnecting does not yield a
1432 * message to be sent. Send in progress message to avoid
1433 * D-Bus LimitsExceeded error message.
1435 reply = __connman_error_in_progress(msg);
1437 g_dbus_send_message(connection, reply);
1439 return -EINPROGRESS;
1440 case VPN_PROVIDER_STATE_UNKNOWN:
1441 case VPN_PROVIDER_STATE_IDLE:
1442 case VPN_PROVIDER_STATE_CONNECT:
1443 case VPN_PROVIDER_STATE_READY:
1447 if (provider->driver && provider->driver->connect) {
1448 const char *dbus_sender = dbus_message_get_sender(msg);
1450 dbus_message_ref(msg);
1452 if (dbus_message_has_signature(msg,
1453 DBUS_TYPE_STRING_AS_STRING)) {
1454 const char *sender = NULL;
1456 dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING,
1457 &sender, DBUS_TYPE_INVALID);
1458 if (sender && sender[0])
1459 dbus_sender = sender;
1462 err = provider->driver->connect(provider, connect_cb,
1467 if (err == -EINPROGRESS)
1468 vpn_provider_set_state(provider, VPN_PROVIDER_STATE_CONNECT);
1473 static void connection_removed_signal(struct vpn_provider *provider)
1475 DBusMessage *signal;
1476 DBusMessageIter iter;
1478 signal = dbus_message_new_signal(VPN_MANAGER_PATH,
1479 VPN_MANAGER_INTERFACE, "ConnectionRemoved");
1483 dbus_message_iter_init_append(signal, &iter);
1484 dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
1486 dbus_connection_send(connection, signal, NULL);
1487 dbus_message_unref(signal);
1490 static char *get_ident(const char *path)
1497 pos = strrchr(path, '/');
1504 int __vpn_provider_remove(const char *path)
1506 struct vpn_provider *provider;
1509 DBG("path %s", path);
1511 ident = get_ident(path);
1513 provider = __vpn_provider_lookup(ident);
1515 return __vpn_provider_delete(provider);
1520 int __vpn_provider_delete(struct vpn_provider *provider)
1522 DBG("Deleting VPN %s", provider->identifier);
1524 connection_removed_signal(provider);
1526 provider_unregister(provider);
1528 __connman_storage_remove_provider(provider->identifier);
1530 g_hash_table_remove(provider_hash, provider->identifier);
1535 static void append_ipv4(DBusMessageIter *iter, void *user_data)
1537 struct vpn_provider *provider = user_data;
1538 const char *address, *gateway, *peer;
1540 address = __vpn_ipconfig_get_local(provider->ipconfig_ipv4);
1543 struct in_addr netmask;
1547 prefixlen = __vpn_ipconfig_get_prefixlen(
1548 provider->ipconfig_ipv4);
1550 addr = 0xffffffff << (32 - prefixlen);
1551 netmask.s_addr = htonl(addr);
1552 mask = inet_ntoa(netmask);
1554 connman_dbus_dict_append_basic(iter, "Address",
1555 DBUS_TYPE_STRING, &address);
1557 connman_dbus_dict_append_basic(iter, "Netmask",
1558 DBUS_TYPE_STRING, &mask);
1561 gateway = __vpn_ipconfig_get_gateway(provider->ipconfig_ipv4);
1563 connman_dbus_dict_append_basic(iter, "Gateway",
1564 DBUS_TYPE_STRING, &gateway);
1566 peer = __vpn_ipconfig_get_peer(provider->ipconfig_ipv4);
1568 connman_dbus_dict_append_basic(iter, "Peer",
1569 DBUS_TYPE_STRING, &peer);
1572 static void append_ipv6(DBusMessageIter *iter, void *user_data)
1574 struct vpn_provider *provider = user_data;
1575 const char *address, *gateway, *peer;
1577 address = __vpn_ipconfig_get_local(provider->ipconfig_ipv6);
1579 unsigned char prefixlen;
1581 connman_dbus_dict_append_basic(iter, "Address",
1582 DBUS_TYPE_STRING, &address);
1584 prefixlen = __vpn_ipconfig_get_prefixlen(
1585 provider->ipconfig_ipv6);
1587 connman_dbus_dict_append_basic(iter, "PrefixLength",
1588 DBUS_TYPE_BYTE, &prefixlen);
1591 gateway = __vpn_ipconfig_get_gateway(provider->ipconfig_ipv6);
1593 connman_dbus_dict_append_basic(iter, "Gateway",
1594 DBUS_TYPE_STRING, &gateway);
1596 peer = __vpn_ipconfig_get_peer(provider->ipconfig_ipv6);
1598 connman_dbus_dict_append_basic(iter, "Peer",
1599 DBUS_TYPE_STRING, &peer);
1602 static const char *state2string(enum vpn_provider_state state)
1605 case VPN_PROVIDER_STATE_UNKNOWN:
1607 case VPN_PROVIDER_STATE_IDLE:
1609 case VPN_PROVIDER_STATE_CONNECT:
1610 return "configuration";
1611 case VPN_PROVIDER_STATE_READY:
1613 case VPN_PROVIDER_STATE_DISCONNECT:
1614 return "disconnect";
1615 case VPN_PROVIDER_STATE_FAILURE:
1622 static void append_nameservers(DBusMessageIter *iter, char **servers)
1628 for (i = 0; servers[i]; i++) {
1629 DBG("servers[%d] %s", i, servers[i]);
1630 dbus_message_iter_append_basic(iter,
1631 DBUS_TYPE_STRING, &servers[i]);
1635 static void append_dns(DBusMessageIter *iter, void *user_data)
1637 struct vpn_provider *provider = user_data;
1639 if (provider->nameservers)
1640 append_nameservers(iter, provider->nameservers);
1643 static int provider_indicate_state(struct vpn_provider *provider,
1644 enum vpn_provider_state state)
1647 enum vpn_provider_state old_state;
1649 str = state2string(state);
1650 DBG("provider %p state %s/%d", provider, str, state);
1654 old_state = provider->state;
1655 provider->state = state;
1657 if (state == VPN_PROVIDER_STATE_READY) {
1658 connman_dbus_property_changed_basic(provider->path,
1659 VPN_CONNECTION_INTERFACE, "Index",
1660 DBUS_TYPE_INT32, &provider->index);
1662 if (provider->family == AF_INET)
1663 connman_dbus_property_changed_dict(provider->path,
1664 VPN_CONNECTION_INTERFACE, "IPv4",
1665 append_ipv4, provider);
1666 else if (provider->family == AF_INET6)
1667 connman_dbus_property_changed_dict(provider->path,
1668 VPN_CONNECTION_INTERFACE, "IPv6",
1669 append_ipv6, provider);
1671 connman_dbus_property_changed_array(provider->path,
1672 VPN_CONNECTION_INTERFACE,
1675 append_dns, provider);
1677 if (provider->domain)
1678 connman_dbus_property_changed_basic(provider->path,
1679 VPN_CONNECTION_INTERFACE,
1685 if (old_state != state)
1686 connman_dbus_property_changed_basic(provider->path,
1687 VPN_CONNECTION_INTERFACE, "State",
1688 DBUS_TYPE_STRING, &str);
1693 static void append_state(DBusMessageIter *iter,
1694 struct vpn_provider *provider)
1698 switch (provider->state) {
1699 case VPN_PROVIDER_STATE_UNKNOWN:
1700 case VPN_PROVIDER_STATE_IDLE:
1703 case VPN_PROVIDER_STATE_CONNECT:
1704 str = "configuration";
1706 case VPN_PROVIDER_STATE_READY:
1709 case VPN_PROVIDER_STATE_DISCONNECT:
1712 case VPN_PROVIDER_STATE_FAILURE:
1717 connman_dbus_dict_append_basic(iter, "State",
1718 DBUS_TYPE_STRING, &str);
1721 static void append_properties(DBusMessageIter *iter,
1722 struct vpn_provider *provider)
1724 DBusMessageIter dict;
1725 GHashTableIter hash;
1726 gpointer value, key;
1727 dbus_bool_t immutable;
1729 connman_dbus_dict_open(iter, &dict);
1731 append_state(&dict, provider);
1734 connman_dbus_dict_append_basic(&dict, "Type",
1735 DBUS_TYPE_STRING, &provider->type);
1738 connman_dbus_dict_append_basic(&dict, "Name",
1739 DBUS_TYPE_STRING, &provider->name);
1742 connman_dbus_dict_append_basic(&dict, "Host",
1743 DBUS_TYPE_STRING, &provider->host);
1744 if (provider->index >= 0)
1745 connman_dbus_dict_append_basic(&dict, "Index",
1746 DBUS_TYPE_INT32, &provider->index);
1747 if (provider->domain)
1748 connman_dbus_dict_append_basic(&dict, "Domain",
1749 DBUS_TYPE_STRING, &provider->domain);
1751 immutable = provider->immutable;
1752 connman_dbus_dict_append_basic(&dict, "Immutable", DBUS_TYPE_BOOLEAN,
1755 if (provider->family == AF_INET)
1756 connman_dbus_dict_append_dict(&dict, "IPv4", append_ipv4,
1758 else if (provider->family == AF_INET6)
1759 connman_dbus_dict_append_dict(&dict, "IPv6", append_ipv6,
1762 connman_dbus_dict_append_array(&dict, "Nameservers",
1763 DBUS_TYPE_STRING, append_dns, provider);
1765 connman_dbus_dict_append_array(&dict, "UserRoutes",
1766 DBUS_TYPE_DICT_ENTRY, append_routes,
1767 provider->user_routes);
1769 connman_dbus_dict_append_array(&dict, "ServerRoutes",
1770 DBUS_TYPE_DICT_ENTRY, append_routes,
1773 if (provider->setting_strings) {
1774 g_hash_table_iter_init(&hash, provider->setting_strings);
1776 while (g_hash_table_iter_next(&hash, &key, &value)) {
1777 struct vpn_setting *setting = value;
1779 if (!setting->hide_value &&
1781 connman_dbus_dict_append_basic(&dict, key,
1787 connman_dbus_dict_close(iter, &dict);
1790 static void connection_added_signal(struct vpn_provider *provider)
1792 DBusMessage *signal;
1793 DBusMessageIter iter;
1795 signal = dbus_message_new_signal(VPN_MANAGER_PATH,
1796 VPN_MANAGER_INTERFACE, "ConnectionAdded");
1800 dbus_message_iter_init_append(signal, &iter);
1801 dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
1803 append_properties(&iter, provider);
1805 dbus_connection_send(connection, signal, NULL);
1806 dbus_message_unref(signal);
1809 static bool check_host(char **hosts, char *host)
1816 for (i = 0; hosts[i]; i++) {
1817 if (g_strcmp0(hosts[i], host) == 0)
1824 static void provider_append_routes(gpointer key, gpointer value,
1827 struct vpn_route *route = value;
1828 struct vpn_provider *provider = user_data;
1829 int index = provider->index;
1835 * If the VPN administrator/user has given a route to
1836 * VPN server, then we must discard that because the
1837 * server cannot be contacted via VPN tunnel.
1839 if (check_host(provider->host_ip, route->network)) {
1840 DBG("Discarding VPN route to %s via %s at index %d",
1841 route->network, route->gateway, index);
1845 if (route->family == AF_INET6) {
1846 unsigned char prefix_len = atoi(route->netmask);
1848 connman_inet_add_ipv6_network_route(index, route->network,
1852 connman_inet_add_network_route(index, route->network,
1858 static int set_connected(struct vpn_provider *provider,
1861 struct vpn_ipconfig *ipconfig;
1863 DBG("provider %p id %s connected %d", provider,
1864 provider->identifier, connected);
1867 if (provider->family == AF_INET6)
1868 ipconfig = provider->ipconfig_ipv6;
1870 ipconfig = provider->ipconfig_ipv4;
1872 __vpn_ipconfig_address_add(ipconfig, provider->family);
1875 __vpn_ipconfig_gateway_add(ipconfig, provider->family);
1877 provider_indicate_state(provider,
1878 VPN_PROVIDER_STATE_READY);
1880 g_hash_table_foreach(provider->routes, provider_append_routes,
1883 g_hash_table_foreach(provider->user_routes,
1884 provider_append_routes, provider);
1887 provider_indicate_state(provider,
1888 VPN_PROVIDER_STATE_DISCONNECT);
1890 provider_indicate_state(provider,
1891 VPN_PROVIDER_STATE_IDLE);
1897 int vpn_provider_set_state(struct vpn_provider *provider,
1898 enum vpn_provider_state state)
1904 case VPN_PROVIDER_STATE_UNKNOWN:
1906 case VPN_PROVIDER_STATE_IDLE:
1907 return set_connected(provider, false);
1908 case VPN_PROVIDER_STATE_CONNECT:
1909 return provider_indicate_state(provider, state);
1910 case VPN_PROVIDER_STATE_READY:
1911 return set_connected(provider, true);
1912 case VPN_PROVIDER_STATE_DISCONNECT:
1913 return provider_indicate_state(provider, state);
1914 case VPN_PROVIDER_STATE_FAILURE:
1915 return provider_indicate_state(provider, state);
1920 void vpn_provider_add_error(struct vpn_provider *provider,
1921 enum vpn_provider_error error)
1924 case VPN_PROVIDER_ERROR_UNKNOWN:
1926 case VPN_PROVIDER_ERROR_CONNECT_FAILED:
1927 ++provider->conn_error_counter;
1929 case VPN_PROVIDER_ERROR_LOGIN_FAILED:
1930 case VPN_PROVIDER_ERROR_AUTH_FAILED:
1931 ++provider->auth_error_counter;
1936 int vpn_provider_indicate_error(struct vpn_provider *provider,
1937 enum vpn_provider_error error)
1939 DBG("provider %p id %s error %d", provider, provider->identifier,
1942 vpn_provider_set_state(provider, VPN_PROVIDER_STATE_FAILURE);
1944 vpn_provider_add_error(provider, error);
1946 if (provider->driver && provider->driver->set_state)
1947 provider->driver->set_state(provider, provider->state);
1952 static int connection_unregister(struct vpn_provider *provider)
1954 DBG("provider %p path %s", provider, provider->path);
1956 if (!provider->path)
1959 g_dbus_unregister_interface(connection, provider->path,
1960 VPN_CONNECTION_INTERFACE);
1962 g_free(provider->path);
1963 provider->path = NULL;
1968 static int connection_register(struct vpn_provider *provider)
1970 DBG("provider %p path %s", provider, provider->path);
1975 provider->path = g_strdup_printf("%s/connection/%s", VPN_PATH,
1976 provider->identifier);
1978 g_dbus_register_interface(connection, provider->path,
1979 VPN_CONNECTION_INTERFACE,
1980 connection_methods, connection_signals,
1981 NULL, provider, NULL);
1986 static void unregister_provider(gpointer data)
1988 struct vpn_provider *provider = data;
1990 configuration_count_del();
1992 connection_unregister(provider);
1994 /* If the provider has any DNS resolver queries pending,
1995 * they need to be cleared here because the unref will not
1996 * be able to do that (because the provider_resolv_host_addr()
1997 * has increased the ref count by 1). This is quite rare as
1998 * normally the resolving either returns a value or has a
1999 * timeout which clears the memory. Typically resolv_result() will
2000 * unref the provider but in this case that call has not yet
2003 if (provider->resolv)
2004 vpn_provider_unref(provider);
2006 vpn_provider_unref(provider);
2009 static void provider_initialize(struct vpn_provider *provider)
2011 DBG("provider %p", provider);
2013 provider->index = 0;
2015 provider->name = NULL;
2016 provider->type = NULL;
2017 provider->domain = NULL;
2018 provider->identifier = NULL;
2019 provider->immutable = false;
2020 provider->user_networks = NULL;
2021 provider->routes = g_hash_table_new_full(g_direct_hash, g_direct_equal,
2023 provider->user_routes = g_hash_table_new_full(g_str_hash, g_str_equal,
2024 g_free, free_route);
2025 provider->setting_strings = g_hash_table_new_full(g_str_hash,
2026 g_str_equal, g_free, free_setting);
2029 static struct vpn_provider *vpn_provider_new(void)
2031 struct vpn_provider *provider;
2033 provider = g_try_new0(struct vpn_provider, 1);
2037 provider->refcount = 1;
2039 DBG("provider %p", provider);
2040 provider_initialize(provider);
2045 static struct vpn_provider *vpn_provider_get(const char *identifier)
2047 struct vpn_provider *provider;
2049 provider = g_hash_table_lookup(provider_hash, identifier);
2053 provider = vpn_provider_new();
2057 DBG("provider %p", provider);
2059 provider->identifier = g_strdup(identifier);
2061 g_hash_table_insert(provider_hash, provider->identifier, provider);
2063 configuration_count_add();
2068 static void vpn_provider_put(const char *identifier)
2070 configuration_count_del();
2072 g_hash_table_remove(provider_hash, identifier);
2075 static void provider_dbus_ident(char *ident)
2077 int i, len = strlen(ident);
2079 for (i = 0; i < len; i++) {
2080 if (ident[i] >= '0' && ident[i] <= '9')
2082 if (ident[i] >= 'a' && ident[i] <= 'z')
2084 if (ident[i] >= 'A' && ident[i] <= 'Z')
2090 static struct vpn_provider *provider_create_from_keyfile(GKeyFile *keyfile,
2093 struct vpn_provider *provider;
2095 if (!keyfile || !ident)
2098 provider = __vpn_provider_lookup(ident);
2100 provider = vpn_provider_get(ident);
2102 DBG("can not create provider");
2106 provider_load_from_keyfile(provider, keyfile);
2108 if (!provider->name || !provider->host ||
2109 !provider->domain) {
2110 DBG("cannot get name, host or domain");
2111 vpn_provider_unref(provider);
2115 if (provider_register(provider) == 0)
2116 connection_register(provider);
2121 static void provider_create_all_from_type(const char *provider_type)
2128 DBG("provider type %s", provider_type);
2130 providers = __connman_storage_get_providers();
2135 for (i = 0; providers[i]; i += 1) {
2137 if (strncmp(providers[i], "provider_", 9) != 0)
2140 id = providers[i] + 9;
2141 keyfile = __connman_storage_load_provider(id);
2146 type = __vpn_config_get_string(keyfile, id, "Type", NULL);
2148 DBG("keyfile %p id %s type %s", keyfile, id, type);
2150 if (strcmp(provider_type, type) != 0) {
2152 g_key_file_free(keyfile);
2156 if (!provider_create_from_keyfile(keyfile, id))
2157 DBG("could not create provider");
2160 g_key_file_free(keyfile);
2162 g_strfreev(providers);
2165 #if !defined TIZEN_EXT
2166 char *__vpn_provider_create_identifier(const char *host, const char *domain)
2171 ident = g_strdup_printf("%s_%s", host, domain);
2173 ident = g_strdup_printf("%s", host);
2175 provider_dbus_ident(ident);
2180 char *__vpn_provider_create_identifier(const char *host, const char *domain, const char *name)
2185 ident = g_strdup_printf("%s_%s_%s", host, domain, name);
2187 ident = g_strdup_printf("%s_%s", host, name);
2191 provider_dbus_ident(ident);
2197 int __vpn_provider_create(DBusMessage *msg)
2199 struct vpn_provider *provider;
2200 DBusMessageIter iter, array;
2201 const char *type = NULL, *name = NULL;
2202 const char *host = NULL, *domain = NULL;
2203 GSList *networks = NULL;
2207 dbus_message_iter_init(msg, &iter);
2208 dbus_message_iter_recurse(&iter, &array);
2210 while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_DICT_ENTRY) {
2211 DBusMessageIter entry, value;
2214 dbus_message_iter_recurse(&array, &entry);
2215 dbus_message_iter_get_basic(&entry, &key);
2217 dbus_message_iter_next(&entry);
2218 dbus_message_iter_recurse(&entry, &value);
2220 switch (dbus_message_iter_get_arg_type(&value)) {
2221 case DBUS_TYPE_STRING:
2222 if (g_str_equal(key, "Type"))
2223 dbus_message_iter_get_basic(&value, &type);
2224 else if (g_str_equal(key, "Name"))
2225 dbus_message_iter_get_basic(&value, &name);
2226 else if (g_str_equal(key, "Host"))
2227 dbus_message_iter_get_basic(&value, &host);
2228 else if (g_str_equal(key, "VPN.Domain") ||
2229 g_str_equal(key, "Domain"))
2230 dbus_message_iter_get_basic(&value, &domain);
2232 case DBUS_TYPE_ARRAY:
2233 if (g_str_equal(key, "UserRoutes"))
2234 networks = get_user_networks(&value);
2238 dbus_message_iter_next(&array);
2244 DBG("Type %s name %s networks %p", type, name, networks);
2249 #if !defined TIZEN_EXT
2250 ident = __vpn_provider_create_identifier(host, domain);
2252 ident = __vpn_provider_create_identifier(host, domain, name);
2254 DBG("ident %s", ident);
2256 provider = __vpn_provider_lookup(ident);
2258 provider = vpn_provider_get(ident);
2260 DBG("can not create provider");
2265 provider->host = g_strdup(host);
2266 provider->domain = g_strdup(domain);
2267 provider->name = g_strdup(name);
2268 provider->type = g_strdup(type);
2270 if (provider_register(provider) == 0)
2271 vpn_provider_load(provider);
2273 provider_resolv_host_addr(provider);
2277 g_slist_free_full(provider->user_networks, free_route);
2278 provider->user_networks = networks;
2279 set_user_networks(provider, provider->user_networks);
2282 dbus_message_iter_init(msg, &iter);
2283 dbus_message_iter_recurse(&iter, &array);
2285 while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_DICT_ENTRY) {
2286 DBusMessageIter entry, value;
2287 const char *key, *str;
2289 dbus_message_iter_recurse(&array, &entry);
2290 dbus_message_iter_get_basic(&entry, &key);
2292 dbus_message_iter_next(&entry);
2293 dbus_message_iter_recurse(&entry, &value);
2295 switch (dbus_message_iter_get_arg_type(&value)) {
2296 case DBUS_TYPE_STRING:
2297 dbus_message_iter_get_basic(&value, &str);
2298 vpn_provider_set_string(provider, key, str);
2302 dbus_message_iter_next(&array);
2307 vpn_provider_save(provider);
2309 err = provider_register(provider);
2310 if (err != 0 && err != -EALREADY)
2313 connection_register(provider);
2315 DBG("provider %p index %d path %s", provider, provider->index,
2318 g_dbus_send_reply(connection, msg,
2319 DBUS_TYPE_OBJECT_PATH, &provider->path,
2322 connection_added_signal(provider);
2327 static const char *get_string(GHashTable *settings, const char *key)
2329 DBG("settings %p key %s", settings, key);
2331 return g_hash_table_lookup(settings, key);
2334 static GSList *parse_user_networks(const char *network_str)
2336 GSList *networks = NULL;
2343 elems = g_strsplit(network_str, ",", 0);
2348 struct vpn_route *vpn_route;
2349 char *network, *netmask, *gateway;
2353 route = g_strsplit(elems[i], "/", 0);
2358 if (!network || network[0] == '\0')
2361 family = connman_inet_check_ipaddress(network);
2363 DBG("Cannot get address family of %s (%d/%s)", network,
2364 family, gai_strerror(family));
2375 DBG("Unsupported address family %d", family);
2380 if (!netmask || netmask[0] == '\0')
2385 vpn_route = g_try_new0(struct vpn_route, 1);
2391 vpn_route->family = family;
2392 vpn_route->network = g_strdup(network);
2393 vpn_route->netmask = g_strdup(netmask);
2394 vpn_route->gateway = g_strdup(gateway);
2396 DBG("route %s/%s%s%s", network, netmask,
2397 gateway ? " via " : "", gateway ? gateway : "");
2399 networks = g_slist_prepend(networks, vpn_route);
2408 return g_slist_reverse(networks);
2411 int __vpn_provider_create_from_config(GHashTable *settings,
2412 const char *config_ident,
2413 const char *config_entry)
2415 struct vpn_provider *provider;
2416 const char *type, *name, *host, *domain, *networks_str;
2419 GHashTableIter hash;
2420 gpointer value, key;
2423 type = get_string(settings, "Type");
2424 name = get_string(settings, "Name");
2425 host = get_string(settings, "Host");
2426 domain = get_string(settings, "Domain");
2427 networks_str = get_string(settings, "Networks");
2428 networks = parse_user_networks(networks_str);
2435 DBG("type %s name %s networks %s", type, name, networks_str);
2437 if (!type || !name) {
2442 #if !defined TIZEN_EXT
2443 ident = __vpn_provider_create_identifier(host, domain);
2445 ident = __vpn_provider_create_identifier(host, domain, name);
2447 DBG("ident %s", ident);
2449 provider = __vpn_provider_lookup(ident);
2451 provider = vpn_provider_get(ident);
2453 DBG("can not create provider");
2458 provider->host = g_strdup(host);
2459 provider->domain = g_strdup(domain);
2460 provider->name = g_strdup(name);
2461 provider->type = g_ascii_strdown(type, -1);
2463 provider->config_file = g_strdup(config_ident);
2464 provider->config_entry = g_strdup(config_entry);
2466 provider_resolv_host_addr(provider);
2470 g_slist_free_full(provider->user_networks, free_route);
2471 provider->user_networks = networks;
2472 set_user_networks(provider, provider->user_networks);
2475 g_hash_table_iter_init(&hash, settings);
2477 while (g_hash_table_iter_next(&hash, &key, &value))
2478 __vpn_provider_set_string_immutable(provider, key, value);
2480 provider->immutable = true;
2482 vpn_provider_save(provider);
2484 err = provider_register(provider);
2485 if (err != 0 && err != -EALREADY)
2488 connection_register(provider);
2490 DBG("provider %p index %d path %s", provider, provider->index,
2493 connection_added_signal(provider);
2500 vpn_provider_put(ident);
2502 g_slist_free_full(networks, free_route);
2507 static void append_connection_structs(DBusMessageIter *iter, void *user_data)
2509 DBusMessageIter entry;
2510 GHashTableIter hash;
2511 gpointer value, key;
2513 g_hash_table_iter_init(&hash, provider_hash);
2515 while (g_hash_table_iter_next(&hash, &key, &value)) {
2516 struct vpn_provider *provider = value;
2518 #if defined TIZEN_EXT
2519 DBG("provider %p", provider);
2521 DBG("path %s", provider->path);
2524 if (!provider->identifier)
2527 dbus_message_iter_open_container(iter, DBUS_TYPE_STRUCT,
2529 dbus_message_iter_append_basic(&entry, DBUS_TYPE_OBJECT_PATH,
2531 append_properties(&entry, provider);
2532 dbus_message_iter_close_container(iter, &entry);
2536 DBusMessage *__vpn_provider_get_connections(DBusMessage *msg)
2542 reply = dbus_message_new_method_return(msg);
2546 __connman_dbus_append_objpath_dict_array(reply,
2547 append_connection_structs, NULL);
2552 const char *vpn_provider_get_ident(struct vpn_provider *provider)
2557 return provider->identifier;
2560 static int set_string(struct vpn_provider *provider,
2561 const char *key, const char *value,
2562 bool hide_value, bool immutable)
2564 DBG("provider %p key %s immutable %s value %s", provider, key,
2565 immutable ? "yes" : "no",
2566 hide_value ? "<not printed>" : value);
2568 if (g_str_equal(key, "Type")) {
2569 if (!g_strcmp0(provider->type, value))
2572 g_free(provider->type);
2573 provider->type = g_ascii_strdown(value, -1);
2574 send_value(provider->path, "Type", provider->type);
2575 } else if (g_str_equal(key, "Name")) {
2576 if (!g_strcmp0(provider->name, value))
2579 g_free(provider->name);
2580 provider->name = g_strdup(value);
2581 send_value(provider->path, "Name", provider->name);
2582 } else if (g_str_equal(key, "Host")) {
2583 if (!g_strcmp0(provider->host, value))
2586 g_free(provider->host);
2587 provider->host = g_strdup(value);
2588 send_value(provider->path, "Host", provider->host);
2589 } else if (g_str_equal(key, "VPN.Domain") ||
2590 g_str_equal(key, "Domain")) {
2591 if (!g_strcmp0(provider->domain, value))
2594 g_free(provider->domain);
2595 provider->domain = g_strdup(value);
2596 send_value(provider->path, "Domain", provider->domain);
2598 struct vpn_setting *setting;
2599 bool replace = true;
2601 setting = g_hash_table_lookup(provider->setting_strings, key);
2603 if (!immutable && setting->immutable) {
2604 DBG("Trying to set immutable variable %s", key);
2606 } else if (!g_strcmp0(setting->value, value)) {
2610 g_free(setting->value);
2613 setting = g_try_new0(struct vpn_setting, 1);
2618 setting->value = g_strdup(value);
2619 setting->hide_value = hide_value;
2622 setting->immutable = true;
2625 send_value(provider->path, key, setting->value);
2628 g_hash_table_replace(provider->setting_strings,
2629 g_strdup(key), setting);
2635 int vpn_provider_set_string(struct vpn_provider *provider,
2636 const char *key, const char *value)
2638 return set_string(provider, key, value, false, false);
2641 int vpn_provider_set_string_hide_value(struct vpn_provider *provider,
2642 const char *key, const char *value)
2644 return set_string(provider, key, value, true, false);
2647 int __vpn_provider_set_string_immutable(struct vpn_provider *provider,
2648 const char *key, const char *value)
2650 return set_string(provider, key, value, false, true);
2653 const char *vpn_provider_get_string(struct vpn_provider *provider,
2656 struct vpn_setting *setting;
2658 DBG("provider %p key %s", provider, key);
2660 if (g_str_equal(key, "Type"))
2661 return provider->type;
2662 else if (g_str_equal(key, "Name"))
2663 return provider->name;
2664 else if (g_str_equal(key, "Host"))
2665 return provider->host;
2666 else if (g_str_equal(key, "HostIP")) {
2667 if (!provider->host_ip ||
2668 !provider->host_ip[0])
2669 return provider->host;
2671 return provider->host_ip[0];
2672 } else if (g_str_equal(key, "VPN.Domain") ||
2673 g_str_equal(key, "Domain"))
2674 return provider->domain;
2676 setting = g_hash_table_lookup(provider->setting_strings, key);
2680 return setting->value;
2683 bool vpn_provider_get_boolean(struct vpn_provider *provider, const char *key,
2686 struct vpn_setting *setting;
2688 connman_info("provider %p key %s", provider, key);
2690 setting = g_hash_table_lookup(provider->setting_strings, key);
2691 if (!setting || !setting->value)
2692 return default_value;
2694 if (!g_strcmp0(setting->value, "true"))
2697 if (!g_strcmp0(setting->value, "false"))
2700 return default_value;
2703 bool vpn_provider_get_string_immutable(struct vpn_provider *provider,
2706 struct vpn_setting *setting;
2708 /* These values can be changed if the provider is not immutable */
2709 if (g_str_equal(key, "Type")) {
2710 return provider->immutable;
2711 } else if (g_str_equal(key, "Name")) {
2712 return provider->immutable;
2713 } else if (g_str_equal(key, "Host")) {
2714 return provider->immutable;
2715 } else if (g_str_equal(key, "HostIP")) {
2716 return provider->immutable;
2717 } else if (g_str_equal(key, "VPN.Domain") ||
2718 g_str_equal(key, "Domain")) {
2719 return provider->immutable;
2722 setting = g_hash_table_lookup(provider->setting_strings, key);
2724 return true; /* Not found, regard as immutable - no changes */
2726 return setting->immutable;
2729 bool __vpn_provider_check_routes(struct vpn_provider *provider)
2734 if (provider->user_routes &&
2735 g_hash_table_size(provider->user_routes) > 0)
2738 if (provider->routes &&
2739 g_hash_table_size(provider->routes) > 0)
2745 void *vpn_provider_get_data(struct vpn_provider *provider)
2747 return provider->driver_data;
2750 void vpn_provider_set_data(struct vpn_provider *provider, void *data)
2752 provider->driver_data = data;
2755 void *vpn_provider_get_plugin_data(struct vpn_provider *provider)
2757 #if defined TIZEN_EXT
2761 return provider->plugin_data;
2764 void vpn_provider_set_plugin_data(struct vpn_provider *provider, void *data)
2766 provider->plugin_data = data;
2769 void vpn_provider_set_index(struct vpn_provider *provider, int index)
2771 DBG("index %d provider %p", index, provider);
2773 if (!provider->ipconfig_ipv4) {
2774 provider->ipconfig_ipv4 = __vpn_ipconfig_create(index,
2776 if (!provider->ipconfig_ipv4) {
2777 DBG("Couldn't create ipconfig for IPv4");
2782 __vpn_ipconfig_set_index(provider->ipconfig_ipv4, index);
2784 if (!provider->ipconfig_ipv6) {
2785 provider->ipconfig_ipv6 = __vpn_ipconfig_create(index,
2787 if (!provider->ipconfig_ipv6) {
2788 DBG("Couldn't create ipconfig for IPv6");
2793 __vpn_ipconfig_set_index(provider->ipconfig_ipv6, index);
2796 provider->index = index;
2799 int vpn_provider_get_index(struct vpn_provider *provider)
2801 return provider->index;
2804 int vpn_provider_set_ipaddress(struct vpn_provider *provider,
2805 struct connman_ipaddress *ipaddress)
2807 struct vpn_ipconfig *ipconfig = NULL;
2809 switch (ipaddress->family) {
2811 ipconfig = provider->ipconfig_ipv4;
2814 ipconfig = provider->ipconfig_ipv6;
2820 DBG("provider %p state %d ipconfig %p family %d", provider,
2821 provider->state, ipconfig, ipaddress->family);
2826 provider->family = ipaddress->family;
2828 if (provider->state == VPN_PROVIDER_STATE_CONNECT ||
2829 provider->state == VPN_PROVIDER_STATE_READY) {
2830 struct connman_ipaddress *addr =
2831 __vpn_ipconfig_get_address(ipconfig);
2834 * Remember the old address so that we can remove it in notify
2835 * function in plugins/vpn.c if we ever restart
2837 if (ipaddress->family == AF_INET6) {
2838 connman_ipaddress_free(provider->prev_ipv6_addr);
2839 provider->prev_ipv6_addr =
2840 connman_ipaddress_copy(addr);
2842 connman_ipaddress_free(provider->prev_ipv4_addr);
2843 provider->prev_ipv4_addr =
2844 connman_ipaddress_copy(addr);
2848 if (ipaddress->local) {
2849 __vpn_ipconfig_set_local(ipconfig, ipaddress->local);
2850 __vpn_ipconfig_set_peer(ipconfig, ipaddress->peer);
2851 __vpn_ipconfig_set_broadcast(ipconfig, ipaddress->broadcast);
2852 __vpn_ipconfig_set_gateway(ipconfig, ipaddress->gateway);
2853 __vpn_ipconfig_set_prefixlen(ipconfig, ipaddress->prefixlen);
2859 int vpn_provider_set_pac(struct vpn_provider *provider,
2862 DBG("provider %p pac %s", provider, pac);
2868 int vpn_provider_set_domain(struct vpn_provider *provider,
2871 DBG("provider %p domain %s", provider, domain);
2873 g_free(provider->domain);
2874 provider->domain = g_strdup(domain);
2879 int vpn_provider_set_nameservers(struct vpn_provider *provider,
2880 const char *nameservers)
2882 DBG("provider %p nameservers %s", provider, nameservers);
2884 g_strfreev(provider->nameservers);
2885 provider->nameservers = NULL;
2890 provider->nameservers = g_strsplit_set(nameservers, ", ", 0);
2895 static int route_env_parse(struct vpn_provider *provider, const char *key,
2896 int *family, unsigned long *idx,
2897 enum vpn_provider_route_type *type)
2902 DBG("name %s", provider->name);
2904 if (provider->driver && provider->driver->route_env_parse)
2905 return provider->driver->route_env_parse(provider, key, family, idx,
2911 int vpn_provider_append_route(struct vpn_provider *provider,
2912 const char *key, const char *value)
2914 struct vpn_route *route;
2915 int ret, family = 0;
2916 unsigned long idx = 0;
2917 enum vpn_provider_route_type type = VPN_PROVIDER_ROUTE_TYPE_NONE;
2919 DBG("key %s value %s", key, value);
2921 ret = route_env_parse(provider, key, &family, &idx, &type);
2925 DBG("idx %lu family %d type %d", idx, family, type);
2927 route = g_hash_table_lookup(provider->routes, GINT_TO_POINTER(idx));
2929 route = g_try_new0(struct vpn_route, 1);
2931 connman_error("out of memory");
2935 route->family = family;
2937 g_hash_table_replace(provider->routes, GINT_TO_POINTER(idx),
2942 case VPN_PROVIDER_ROUTE_TYPE_NONE:
2944 case VPN_PROVIDER_ROUTE_TYPE_MASK:
2945 route->netmask = g_strdup(value);
2947 case VPN_PROVIDER_ROUTE_TYPE_ADDR:
2948 route->network = g_strdup(value);
2950 case VPN_PROVIDER_ROUTE_TYPE_GW:
2951 route->gateway = g_strdup(value);
2955 if (!handle_routes) {
2956 if (route->netmask && route->gateway &&
2958 provider_schedule_changed(provider);
2964 const char *vpn_provider_get_driver_name(struct vpn_provider *provider)
2966 if (!provider->driver)
2969 return provider->driver->name;
2972 const char *vpn_provider_get_save_group(struct vpn_provider *provider)
2974 return provider->identifier;
2977 static gint compare_priority(gconstpointer a, gconstpointer b)
2982 static void clean_provider(gpointer key, gpointer value, gpointer user_data)
2984 struct vpn_provider *provider = value;
2986 if (provider->driver && provider->driver->remove)
2987 provider->driver->remove(provider);
2989 connection_unregister(provider);
2992 int vpn_provider_driver_register(struct vpn_provider_driver *driver)
2994 DBG("driver %p name %s", driver, driver->name);
2996 driver_list = g_slist_insert_sorted(driver_list, driver,
2998 provider_create_all_from_type(driver->name);
3002 void vpn_provider_driver_unregister(struct vpn_provider_driver *driver)
3004 GHashTableIter iter;
3005 gpointer value, key;
3007 DBG("driver %p name %s", driver, driver->name);
3009 driver_list = g_slist_remove(driver_list, driver);
3011 g_hash_table_iter_init(&iter, provider_hash);
3012 while (g_hash_table_iter_next(&iter, &key, &value)) {
3013 struct vpn_provider *provider = value;
3015 if (provider && provider->driver &&
3016 g_strcmp0(provider->driver->name,
3017 driver->name) == 0) {
3018 provider->driver = NULL;
3023 const char *vpn_provider_get_name(struct vpn_provider *provider)
3025 return provider->name;
3028 const char *vpn_provider_get_host(struct vpn_provider *provider)
3030 return provider->host;
3033 const char *vpn_provider_get_path(struct vpn_provider *provider)
3035 return provider->path;
3038 unsigned int vpn_provider_get_authentication_errors(
3039 struct vpn_provider *provider)
3041 return provider->auth_error_counter;
3044 unsigned int vpn_provider_get_connection_errors(
3045 struct vpn_provider *provider)
3047 return provider->conn_error_counter;
3050 void vpn_provider_change_address(struct vpn_provider *provider)
3052 switch (provider->family) {
3054 connman_inet_set_address(provider->index,
3055 __vpn_ipconfig_get_address(provider->ipconfig_ipv4));
3058 connman_inet_set_ipv6_address(provider->index,
3059 __vpn_ipconfig_get_address(provider->ipconfig_ipv6));
3066 void vpn_provider_clear_address(struct vpn_provider *provider, int family)
3068 const char *address;
3071 DBG("provider %p family %d ipv4 %p ipv6 %p", provider, family,
3072 provider->prev_ipv4_addr, provider->prev_ipv6_addr);
3076 if (provider->prev_ipv4_addr) {
3077 connman_ipaddress_get_ip(provider->prev_ipv4_addr,
3080 DBG("ipv4 %s/%d", address, len);
3082 connman_inet_clear_address(provider->index,
3083 provider->prev_ipv4_addr);
3084 connman_ipaddress_free(provider->prev_ipv4_addr);
3085 provider->prev_ipv4_addr = NULL;
3089 if (provider->prev_ipv6_addr) {
3090 connman_ipaddress_get_ip(provider->prev_ipv6_addr,
3093 DBG("ipv6 %s/%d", address, len);
3095 connman_inet_clear_ipv6_address(provider->index,
3098 connman_ipaddress_free(provider->prev_ipv6_addr);
3099 provider->prev_ipv6_addr = NULL;
3107 static int agent_probe(struct connman_agent *agent)
3109 DBG("agent %p", agent);
3113 static void agent_remove(struct connman_agent *agent)
3115 DBG("agent %p", agent);
3118 static struct connman_agent_driver agent_driver = {
3120 .interface = VPN_AGENT_INTERFACE,
3121 .probe = agent_probe,
3122 .remove = agent_remove,
3125 static void remove_unprovisioned_providers(void)
3128 GKeyFile *keyfile, *configkeyfile;
3129 char *file, *section;
3132 providers = __connman_storage_get_providers();
3136 for (; providers[i]; i++) {
3137 char *group = providers[i] + sizeof("provider_") - 1;
3138 file = section = NULL;
3139 keyfile = configkeyfile = NULL;
3141 keyfile = __connman_storage_load_provider(group);
3145 file = __vpn_config_get_string(keyfile, group,
3146 "Config.file", NULL);
3150 section = __vpn_config_get_string(keyfile, group,
3151 "Config.ident", NULL);
3155 configkeyfile = __connman_storage_load_provider_config(file);
3156 if (!configkeyfile) {
3158 * Config file is missing, remove the provisioned
3161 __connman_storage_remove_provider(group);
3165 if (!g_key_file_has_group(configkeyfile, section))
3167 * Config section is missing, remove the provisioned
3170 __connman_storage_remove_provider(group);
3174 g_key_file_free(keyfile);
3177 g_key_file_free(configkeyfile);
3183 g_strfreev(providers);
3186 int __vpn_provider_init(bool do_routes)
3192 handle_routes = do_routes;
3194 err = connman_agent_driver_register(&agent_driver);
3196 connman_error("Cannot register agent driver for %s",
3201 connection = connman_dbus_get_connection();
3203 remove_unprovisioned_providers();
3205 provider_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
3206 NULL, unregister_provider);
3210 void __vpn_provider_cleanup(void)
3214 connman_agent_driver_unregister(&agent_driver);
3216 g_hash_table_foreach(provider_hash, clean_provider, NULL);
3218 g_hash_table_destroy(provider_hash);
3219 provider_hash = NULL;
3221 dbus_connection_unref(connection);