5 * Copyright (C) 2007-2010 Intel Corporation. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 #include <net/if_arp.h>
29 #include <linux/if_link.h>
34 #define IFF_LOWER_UP 0x10000
41 struct connman_ipconfig {
44 enum connman_ipconfig_type type;
46 struct connman_ipconfig *origin;
48 const struct connman_ipconfig_ops *ops;
51 enum connman_ipconfig_method method;
52 struct connman_ipaddress *address;
53 struct connman_ipaddress *system;
56 struct connman_ipdevice {
78 struct connman_ipconfig *config_ipv4;
79 struct connman_ipconfig *config_ipv6;
81 gboolean ipv6_enabled;
84 static GHashTable *ipdevice_hash = NULL;
85 static GList *ipconfig_list = NULL;
87 struct connman_ipaddress *connman_ipaddress_alloc(int family)
89 struct connman_ipaddress *ipaddress;
91 ipaddress = g_try_new0(struct connman_ipaddress, 1);
92 if (ipaddress == NULL)
95 ipaddress->family = family;
96 ipaddress->prefixlen = 0;
97 ipaddress->local = NULL;
98 ipaddress->peer = NULL;
99 ipaddress->broadcast = NULL;
100 ipaddress->gateway = NULL;
105 void connman_ipaddress_free(struct connman_ipaddress *ipaddress)
107 if (ipaddress == NULL)
110 g_free(ipaddress->broadcast);
111 g_free(ipaddress->peer);
112 g_free(ipaddress->local);
113 g_free(ipaddress->gateway);
117 unsigned char __connman_ipconfig_netmask_prefix_len(const char *netmask)
126 mask = inet_network(netmask);
129 /* a valid netmask must be 2^n - 1 */
130 if ((host & (host + 1)) != 0)
134 for (; mask; mask <<= 1)
140 static gboolean check_ipv6_address(const char *address)
142 unsigned char buf[sizeof(struct in6_addr)];
145 err = inet_pton(AF_INET6, address, buf);
152 int connman_ipaddress_set_ipv6(struct connman_ipaddress *ipaddress,
153 const char *address, const char *gateway,
154 unsigned char prefix_length)
156 if (ipaddress == NULL)
159 if (check_ipv6_address(address) == FALSE)
162 if (check_ipv6_address(gateway) == FALSE)
165 DBG("prefix_len %d address %s gateway %s",
166 prefix_length, address, gateway);
168 ipaddress->prefixlen = prefix_length;
170 g_free(ipaddress->local);
171 ipaddress->local = g_strdup(address);
173 g_free(ipaddress->gateway);
174 ipaddress->gateway = g_strdup(gateway);
179 void connman_ipaddress_set_ipv4(struct connman_ipaddress *ipaddress,
180 const char *address, const char *netmask, const char *gateway)
182 if (ipaddress == NULL)
185 ipaddress->prefixlen = __connman_ipconfig_netmask_prefix_len(netmask);
187 g_free(ipaddress->local);
188 ipaddress->local = g_strdup(address);
190 g_free(ipaddress->gateway);
191 ipaddress->gateway = g_strdup(gateway);
194 void connman_ipaddress_clear(struct connman_ipaddress *ipaddress)
196 if (ipaddress == NULL)
199 ipaddress->prefixlen = 0;
201 g_free(ipaddress->local);
202 ipaddress->local = NULL;
204 g_free(ipaddress->peer);
205 ipaddress->peer = NULL;
207 g_free(ipaddress->broadcast);
208 ipaddress->broadcast = NULL;
210 g_free(ipaddress->gateway);
211 ipaddress->gateway = NULL;
214 void connman_ipaddress_copy(struct connman_ipaddress *ipaddress,
215 struct connman_ipaddress *source)
217 if (ipaddress == NULL || source == NULL)
220 ipaddress->family = source->family;
221 ipaddress->prefixlen = source->prefixlen;
223 g_free(ipaddress->local);
224 ipaddress->local = g_strdup(source->local);
226 g_free(ipaddress->peer);
227 ipaddress->peer = g_strdup(source->peer);
229 g_free(ipaddress->broadcast);
230 ipaddress->broadcast = g_strdup(source->broadcast);
232 g_free(ipaddress->gateway);
233 ipaddress->gateway = g_strdup(source->gateway);
236 static void free_address_list(struct connman_ipdevice *ipdevice)
240 for (list = ipdevice->address_list; list; list = list->next) {
241 struct connman_ipaddress *ipaddress = list->data;
243 connman_ipaddress_free(ipaddress);
247 g_slist_free(ipdevice->address_list);
248 ipdevice->address_list = NULL;
251 static struct connman_ipaddress *find_ipaddress(struct connman_ipdevice *ipdevice,
252 unsigned char prefixlen, const char *local)
256 for (list = ipdevice->address_list; list; list = list->next) {
257 struct connman_ipaddress *ipaddress = list->data;
259 if (g_strcmp0(ipaddress->local, local) == 0 &&
260 ipaddress->prefixlen == prefixlen)
267 static const char *type2str(unsigned short type)
272 case ARPHRD_LOOPBACK:
285 static const char *scope2str(unsigned char scope)
297 static gboolean get_ipv6_state(gchar *ifname)
302 gboolean enabled = FALSE;
305 path = g_strdup("/proc/sys/net/ipv6/conf/all/disable_ipv6");
307 path = g_strdup_printf(
308 "/proc/sys/net/ipv6/conf/%s/disable_ipv6", ifname);
313 f = fopen(path, "r");
318 if (fscanf(f, "%d", &disabled) > 0)
326 static void set_ipv6_state(gchar *ifname, gboolean enable)
332 path = g_strdup("/proc/sys/net/ipv6/conf/all/disable_ipv6");
334 path = g_strdup_printf(
335 "/proc/sys/net/ipv6/conf/%s/disable_ipv6", ifname);
340 f = fopen(path, "r+");
355 static void free_ipdevice(gpointer data)
357 struct connman_ipdevice *ipdevice = data;
359 connman_info("%s {remove} index %d", ipdevice->ifname,
362 if (ipdevice->config_ipv4 != NULL) {
363 connman_ipconfig_unref(ipdevice->config_ipv4);
364 ipdevice->config_ipv4 = NULL;
367 if (ipdevice->config_ipv6 != NULL) {
368 connman_ipconfig_unref(ipdevice->config_ipv6);
369 ipdevice->config_ipv6 = NULL;
372 free_address_list(ipdevice);
373 g_free(ipdevice->ipv4_gateway);
374 g_free(ipdevice->ipv6_gateway);
375 g_free(ipdevice->pac);
377 g_free(ipdevice->address);
379 set_ipv6_state(ipdevice->ifname, ipdevice->ipv6_enabled);
381 g_free(ipdevice->ifname);
385 static void __connman_ipconfig_lower_up(struct connman_ipdevice *ipdevice)
387 DBG("ipconfig ipv4 %p ipv6 %p", ipdevice->config_ipv4,
388 ipdevice->config_ipv6);
391 static void __connman_ipconfig_lower_down(struct connman_ipdevice *ipdevice)
393 DBG("ipconfig ipv4 %p ipv6 %p", ipdevice->config_ipv4,
394 ipdevice->config_ipv6);
396 if (ipdevice->config_ipv4)
397 connman_inet_clear_address(ipdevice->index,
398 ipdevice->config_ipv4->address);
400 if (ipdevice->config_ipv6)
401 connman_inet_clear_ipv6_address(ipdevice->index,
402 ipdevice->config_ipv6->address->local,
403 ipdevice->config_ipv6->address->prefixlen);
406 static void update_stats(struct connman_ipdevice *ipdevice,
407 struct rtnl_link_stats *stats)
409 struct connman_service *service;
411 if (stats->rx_packets == 0 && stats->tx_packets == 0)
414 connman_info("%s {RX} %u packets %u bytes", ipdevice->ifname,
415 stats->rx_packets, stats->rx_bytes);
416 connman_info("%s {TX} %u packets %u bytes", ipdevice->ifname,
417 stats->tx_packets, stats->tx_bytes);
419 if (ipdevice->config_ipv4 == NULL && ipdevice->config_ipv6 == NULL)
422 if (ipdevice->config_ipv4)
423 service = connman_ipconfig_get_data(ipdevice->config_ipv4);
424 else if (ipdevice->config_ipv6)
425 service = connman_ipconfig_get_data(ipdevice->config_ipv6);
432 ipdevice->rx_packets = stats->rx_packets;
433 ipdevice->tx_packets = stats->tx_packets;
434 ipdevice->rx_bytes = stats->rx_bytes;
435 ipdevice->tx_bytes = stats->tx_bytes;
436 ipdevice->rx_errors = stats->rx_errors;
437 ipdevice->tx_errors = stats->tx_errors;
438 ipdevice->rx_dropped = stats->rx_dropped;
439 ipdevice->tx_dropped = stats->tx_dropped;
441 __connman_service_notify(service,
442 ipdevice->rx_packets, ipdevice->tx_packets,
443 ipdevice->rx_bytes, ipdevice->tx_bytes,
444 ipdevice->rx_errors, ipdevice->tx_errors,
445 ipdevice->rx_dropped, ipdevice->tx_dropped);
448 void __connman_ipconfig_newlink(int index, unsigned short type,
449 unsigned int flags, const char *address,
451 struct rtnl_link_stats *stats)
453 struct connman_ipdevice *ipdevice;
456 gboolean up = FALSE, down = FALSE;
457 gboolean lower_up = FALSE, lower_down = FALSE;
459 DBG("index %d", index);
461 if (type == ARPHRD_LOOPBACK)
464 ipdevice = g_hash_table_lookup(ipdevice_hash, GINT_TO_POINTER(index));
465 if (ipdevice != NULL)
468 ipdevice = g_try_new0(struct connman_ipdevice, 1);
469 if (ipdevice == NULL)
472 ipdevice->index = index;
473 ipdevice->ifname = connman_inet_ifname(index);
474 ipdevice->type = type;
476 ipdevice->ipv6_enabled = get_ipv6_state(ipdevice->ifname);
478 ipdevice->address = g_strdup(address);
480 g_hash_table_insert(ipdevice_hash, GINT_TO_POINTER(index), ipdevice);
482 connman_info("%s {create} index %d type %d <%s>", ipdevice->ifname,
483 index, type, type2str(type));
488 update_stats(ipdevice, stats);
490 if (flags == ipdevice->flags)
493 if ((ipdevice->flags & IFF_UP) != (flags & IFF_UP)) {
500 if ((ipdevice->flags & (IFF_RUNNING | IFF_LOWER_UP)) !=
501 (flags & (IFF_RUNNING | IFF_LOWER_UP))) {
502 if ((flags & (IFF_RUNNING | IFF_LOWER_UP)) ==
503 (IFF_RUNNING | IFF_LOWER_UP))
505 else if ((flags & (IFF_RUNNING | IFF_LOWER_UP)) == 0)
509 ipdevice->flags = flags;
511 str = g_string_new(NULL);
516 g_string_append(str, "UP");
518 g_string_append(str, "DOWN");
520 if (flags & IFF_RUNNING)
521 g_string_append(str, ",RUNNING");
523 if (flags & IFF_LOWER_UP)
524 g_string_append(str, ",LOWER_UP");
526 connman_info("%s {update} flags %u <%s>", ipdevice->ifname,
529 g_string_free(str, TRUE);
531 for (list = g_list_first(ipconfig_list); list;
532 list = g_list_next(list)) {
533 struct connman_ipconfig *ipconfig = list->data;
535 if (index != ipconfig->index)
538 if (ipconfig->ops == NULL)
541 if (up == TRUE && ipconfig->ops->up)
542 ipconfig->ops->up(ipconfig);
543 if (lower_up == TRUE && ipconfig->ops->lower_up)
544 ipconfig->ops->lower_up(ipconfig);
546 if (lower_down == TRUE && ipconfig->ops->lower_down)
547 ipconfig->ops->lower_down(ipconfig);
548 if (down == TRUE && ipconfig->ops->down)
549 ipconfig->ops->down(ipconfig);
553 __connman_ipconfig_lower_up(ipdevice);
555 __connman_ipconfig_lower_down(ipdevice);
558 void __connman_ipconfig_dellink(int index, struct rtnl_link_stats *stats)
560 struct connman_ipdevice *ipdevice;
563 DBG("index %d", index);
565 ipdevice = g_hash_table_lookup(ipdevice_hash, GINT_TO_POINTER(index));
566 if (ipdevice == NULL)
569 update_stats(ipdevice, stats);
571 for (list = g_list_first(ipconfig_list); list;
572 list = g_list_next(list)) {
573 struct connman_ipconfig *ipconfig = list->data;
575 if (index != ipconfig->index)
578 ipconfig->index = -1;
580 if (ipconfig->ops == NULL)
583 if (ipconfig->ops->lower_down)
584 ipconfig->ops->lower_down(ipconfig);
585 if (ipconfig->ops->down)
586 ipconfig->ops->down(ipconfig);
589 __connman_ipconfig_lower_down(ipdevice);
591 g_hash_table_remove(ipdevice_hash, GINT_TO_POINTER(index));
594 static inline gint check_duplicate_address(gconstpointer a, gconstpointer b)
596 const struct connman_ipaddress *addr1 = a;
597 const struct connman_ipaddress *addr2 = b;
599 if (addr1->prefixlen != addr2->prefixlen)
600 return addr2->prefixlen - addr1->prefixlen;
602 return g_strcmp0(addr1->local, addr2->local);
605 void __connman_ipconfig_newaddr(int index, int family, const char *label,
606 unsigned char prefixlen, const char *address)
608 struct connman_ipdevice *ipdevice;
609 struct connman_ipaddress *ipaddress;
612 DBG("index %d", index);
614 ipdevice = g_hash_table_lookup(ipdevice_hash, GINT_TO_POINTER(index));
615 if (ipdevice == NULL)
618 ipaddress = connman_ipaddress_alloc(family);
619 if (ipaddress == NULL)
622 ipaddress->prefixlen = prefixlen;
623 ipaddress->local = g_strdup(address);
625 if (g_slist_find_custom(ipdevice->address_list, ipaddress,
626 check_duplicate_address)) {
627 connman_ipaddress_free(ipaddress);
631 ipdevice->address_list = g_slist_append(ipdevice->address_list,
634 connman_info("%s {add} address %s/%u label %s family %d",
635 ipdevice->ifname, address, prefixlen, label, family);
637 if (ipdevice->config_ipv4 != NULL && family == AF_INET)
638 connman_ipaddress_copy(ipdevice->config_ipv4->system,
641 else if (ipdevice->config_ipv6 != NULL && family == AF_INET6)
642 connman_ipaddress_copy(ipdevice->config_ipv6->system,
647 if ((ipdevice->flags & (IFF_RUNNING | IFF_LOWER_UP)) != (IFF_RUNNING | IFF_LOWER_UP))
650 for (list = g_list_first(ipconfig_list); list;
651 list = g_list_next(list)) {
652 struct connman_ipconfig *ipconfig = list->data;
654 if (index != ipconfig->index)
657 if (ipconfig->ops == NULL)
660 if (ipconfig->ops->ip_bound)
661 ipconfig->ops->ip_bound(ipconfig);
665 void __connman_ipconfig_deladdr(int index, int family, const char *label,
666 unsigned char prefixlen, const char *address)
668 struct connman_ipdevice *ipdevice;
669 struct connman_ipaddress *ipaddress;
672 DBG("index %d", index);
674 ipdevice = g_hash_table_lookup(ipdevice_hash, GINT_TO_POINTER(index));
675 if (ipdevice == NULL)
678 ipaddress = find_ipaddress(ipdevice, prefixlen, address);
679 if (ipaddress == NULL)
682 ipdevice->address_list = g_slist_remove(ipdevice->address_list,
685 connman_ipaddress_free(ipaddress);
687 connman_info("%s {del} address %s/%u label %s", ipdevice->ifname,
688 address, prefixlen, label);
690 if ((ipdevice->flags & (IFF_RUNNING | IFF_LOWER_UP)) != (IFF_RUNNING | IFF_LOWER_UP))
693 if (g_slist_length(ipdevice->address_list) > 0)
696 for (list = g_list_first(ipconfig_list); list;
697 list = g_list_next(list)) {
698 struct connman_ipconfig *ipconfig = list->data;
700 if (index != ipconfig->index)
703 if (ipconfig->ops == NULL)
706 if (ipconfig->ops->ip_release)
707 ipconfig->ops->ip_release(ipconfig);
711 void __connman_ipconfig_newroute(int index, int family, unsigned char scope,
712 const char *dst, const char *gateway)
714 struct connman_ipdevice *ipdevice;
716 DBG("index %d", index);
718 ipdevice = g_hash_table_lookup(ipdevice_hash, GINT_TO_POINTER(index));
719 if (ipdevice == NULL)
722 if (scope == 0 && g_strcmp0(dst, "0.0.0.0") == 0) {
726 if (family == AF_INET6) {
727 g_free(ipdevice->ipv6_gateway);
728 ipdevice->ipv6_gateway = g_strdup(gateway);
730 if (ipdevice->config_ipv6 != NULL &&
731 ipdevice->config_ipv6->system != NULL) {
732 g_free(ipdevice->config_ipv6->system->gateway);
733 ipdevice->config_ipv6->system->gateway =
737 g_free(ipdevice->ipv4_gateway);
738 ipdevice->ipv4_gateway = g_strdup(gateway);
740 if (ipdevice->config_ipv4 != NULL &&
741 ipdevice->config_ipv4->system != NULL) {
742 g_free(ipdevice->config_ipv4->system->gateway);
743 ipdevice->config_ipv4->system->gateway =
748 for (list = ipdevice->address_list; list; list = list->next) {
749 struct connman_ipaddress *ipaddress = list->data;
751 g_free(ipaddress->gateway);
752 ipaddress->gateway = g_strdup(gateway);
755 for (config_list = g_list_first(ipconfig_list); config_list;
756 config_list = g_list_next(config_list)) {
757 struct connman_ipconfig *ipconfig = config_list->data;
759 if (index != ipconfig->index)
762 if (ipconfig->ops == NULL)
765 if (ipconfig->ops->ip_bound)
766 ipconfig->ops->ip_bound(ipconfig);
770 connman_info("%s {add} route %s gw %s scope %u <%s>",
771 ipdevice->ifname, dst, gateway,
772 scope, scope2str(scope));
775 void __connman_ipconfig_delroute(int index, int family, unsigned char scope,
776 const char *dst, const char *gateway)
778 struct connman_ipdevice *ipdevice;
780 DBG("index %d", index);
782 ipdevice = g_hash_table_lookup(ipdevice_hash, GINT_TO_POINTER(index));
783 if (ipdevice == NULL)
786 if (scope == 0 && g_strcmp0(dst, "0.0.0.0") == 0) {
790 if (family == AF_INET6) {
791 g_free(ipdevice->ipv6_gateway);
792 ipdevice->ipv6_gateway = NULL;
794 if (ipdevice->config_ipv6 != NULL &&
795 ipdevice->config_ipv6->system != NULL) {
796 g_free(ipdevice->config_ipv6->system->gateway);
797 ipdevice->config_ipv6->system->gateway = NULL;
800 g_free(ipdevice->ipv4_gateway);
801 ipdevice->ipv4_gateway = NULL;
803 if (ipdevice->config_ipv4 != NULL &&
804 ipdevice->config_ipv4->system != NULL) {
805 g_free(ipdevice->config_ipv4->system->gateway);
806 ipdevice->config_ipv4->system->gateway = NULL;
810 for (list = ipdevice->address_list; list; list = list->next) {
811 struct connman_ipaddress *ipaddress = list->data;
813 g_free(ipaddress->gateway);
814 ipaddress->gateway = NULL;
817 for (config_list = g_list_first(ipconfig_list); config_list;
818 config_list = g_list_next(config_list)) {
819 struct connman_ipconfig *ipconfig = config_list->data;
821 if (index != ipconfig->index)
824 if (ipconfig->ops == NULL)
827 if (ipconfig->ops->ip_release)
828 ipconfig->ops->ip_release(ipconfig);
832 connman_info("%s {del} route %s gw %s scope %u <%s>",
833 ipdevice->ifname, dst, gateway,
834 scope, scope2str(scope));
837 void __connman_ipconfig_foreach(void (*function) (int index, void *user_data),
842 keys = g_hash_table_get_keys(ipdevice_hash);
846 for (list = g_list_first(keys); list; list = g_list_next(list)) {
847 int index = GPOINTER_TO_INT(list->data);
849 function(index, user_data);
855 unsigned short __connman_ipconfig_get_type(int index)
857 struct connman_ipdevice *ipdevice;
859 ipdevice = g_hash_table_lookup(ipdevice_hash, GINT_TO_POINTER(index));
860 if (ipdevice == NULL)
863 return ipdevice->type;
866 unsigned int __connman_ipconfig_get_flags(int index)
868 struct connman_ipdevice *ipdevice;
870 ipdevice = g_hash_table_lookup(ipdevice_hash, GINT_TO_POINTER(index));
871 if (ipdevice == NULL)
874 return ipdevice->flags;
877 const char *__connman_ipconfig_get_gateway(int index)
879 struct connman_ipdevice *ipdevice;
881 ipdevice = g_hash_table_lookup(ipdevice_hash, GINT_TO_POINTER(index));
882 if (ipdevice == NULL)
885 if (ipdevice->ipv4_gateway != NULL)
886 return ipdevice->ipv4_gateway;
888 if (ipdevice->config_ipv4 != NULL &&
889 ipdevice->config_ipv4->address != NULL)
890 return ipdevice->config_ipv4->address->gateway;
892 if (ipdevice->ipv6_gateway != NULL)
893 return ipdevice->ipv6_gateway;
895 if (ipdevice->config_ipv6 != NULL &&
896 ipdevice->config_ipv6->address != NULL)
897 return ipdevice->config_ipv6->address->gateway;
902 void __connman_ipconfig_set_index(struct connman_ipconfig *ipconfig, int index)
904 ipconfig->index = index;
907 static struct connman_ipconfig *create_ipv6config(int index)
909 struct connman_ipconfig *ipv6config;
911 DBG("index %d", index);
913 ipv6config = g_try_new0(struct connman_ipconfig, 1);
914 if (ipv6config == NULL)
917 ipv6config->refcount = 1;
919 ipv6config->index = index;
920 ipv6config->type = CONNMAN_IPCONFIG_TYPE_IPV6;
921 ipv6config->method = CONNMAN_IPCONFIG_METHOD_AUTO;
923 ipv6config->address = connman_ipaddress_alloc(AF_INET6);
924 if (ipv6config->address == NULL) {
929 ipv6config->system = connman_ipaddress_alloc(AF_INET6);
931 DBG("ipconfig %p", ipv6config);
937 * connman_ipconfig_create:
939 * Allocate a new ipconfig structure.
941 * Returns: a newly-allocated #connman_ipconfig structure
943 struct connman_ipconfig *connman_ipconfig_create(int index,
944 enum connman_ipconfig_type type)
946 struct connman_ipconfig *ipconfig;
948 if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
949 return create_ipv6config(index);
951 DBG("index %d", index);
953 ipconfig = g_try_new0(struct connman_ipconfig, 1);
954 if (ipconfig == NULL)
957 ipconfig->refcount = 1;
959 ipconfig->index = index;
960 ipconfig->type = CONNMAN_IPCONFIG_TYPE_IPV4;
962 ipconfig->address = connman_ipaddress_alloc(AF_INET);
963 if (ipconfig->address == NULL) {
968 ipconfig->system = connman_ipaddress_alloc(AF_INET);
970 DBG("ipconfig %p", ipconfig);
977 * connman_ipconfig_ref:
978 * @ipconfig: ipconfig structure
980 * Increase reference counter of ipconfig
982 struct connman_ipconfig *connman_ipconfig_ref(struct connman_ipconfig *ipconfig)
984 DBG("ipconfig %p refcount %d", ipconfig,
985 g_atomic_int_get(&ipconfig->refcount) + 1);
987 g_atomic_int_inc(&ipconfig->refcount);
993 * connman_ipconfig_unref:
994 * @ipconfig: ipconfig structure
996 * Decrease reference counter of ipconfig
998 void connman_ipconfig_unref(struct connman_ipconfig *ipconfig)
1000 if (ipconfig == NULL)
1003 DBG("ipconfig %p refcount %d", ipconfig,
1004 g_atomic_int_get(&ipconfig->refcount) - 1);
1006 if (g_atomic_int_dec_and_test(&ipconfig->refcount) == TRUE) {
1007 __connman_ipconfig_disable(ipconfig);
1009 connman_ipconfig_set_ops(ipconfig, NULL);
1011 if (ipconfig->origin != NULL) {
1012 connman_ipconfig_unref(ipconfig->origin);
1013 ipconfig->origin = NULL;
1016 connman_ipaddress_free(ipconfig->system);
1017 connman_ipaddress_free(ipconfig->address);
1023 * connman_ipconfig_get_data:
1024 * @ipconfig: ipconfig structure
1026 * Get private data pointer
1028 void *connman_ipconfig_get_data(struct connman_ipconfig *ipconfig)
1030 if (ipconfig == NULL)
1033 return ipconfig->ops_data;
1037 * connman_ipconfig_set_data:
1038 * @ipconfig: ipconfig structure
1039 * @data: data pointer
1041 * Set private data pointer
1043 void connman_ipconfig_set_data(struct connman_ipconfig *ipconfig, void *data)
1045 ipconfig->ops_data = data;
1049 * connman_ipconfig_get_index:
1050 * @ipconfig: ipconfig structure
1052 * Get interface index
1054 int connman_ipconfig_get_index(struct connman_ipconfig *ipconfig)
1056 if (ipconfig == NULL)
1059 if (ipconfig->origin != NULL)
1060 return ipconfig->origin->index;
1062 return ipconfig->index;
1066 * connman_ipconfig_get_ifname:
1067 * @ipconfig: ipconfig structure
1069 * Get interface name
1071 const char *connman_ipconfig_get_ifname(struct connman_ipconfig *ipconfig)
1073 struct connman_ipdevice *ipdevice;
1075 if (ipconfig == NULL)
1078 if (ipconfig->index < 0)
1081 ipdevice = g_hash_table_lookup(ipdevice_hash,
1082 GINT_TO_POINTER(ipconfig->index));
1083 if (ipdevice == NULL)
1086 return ipdevice->ifname;
1090 * connman_ipconfig_set_ops:
1091 * @ipconfig: ipconfig structure
1092 * @ops: operation callbacks
1094 * Set the operation callbacks
1096 void connman_ipconfig_set_ops(struct connman_ipconfig *ipconfig,
1097 const struct connman_ipconfig_ops *ops)
1099 ipconfig->ops = ops;
1103 * connman_ipconfig_set_method:
1104 * @ipconfig: ipconfig structure
1105 * @method: configuration method
1107 * Set the configuration method
1109 int connman_ipconfig_set_method(struct connman_ipconfig *ipconfig,
1110 enum connman_ipconfig_method method)
1112 ipconfig->method = method;
1117 enum connman_ipconfig_method __connman_ipconfig_get_method(struct connman_ipconfig *ipconfig)
1119 if (ipconfig == NULL)
1120 return CONNMAN_IPCONFIG_METHOD_UNKNOWN;
1122 return ipconfig->method;
1126 * connman_ipconfig_bind:
1127 * @ipconfig: ipconfig structure
1128 * @ipaddress: ipaddress structure
1130 * Bind IP address details to configuration
1132 void connman_ipconfig_bind(struct connman_ipconfig *ipconfig,
1133 struct connman_ipaddress *ipaddress)
1135 struct connman_ipconfig *origin;
1137 origin = ipconfig->origin ? ipconfig->origin : ipconfig;
1139 connman_ipaddress_copy(origin->address, ipaddress);
1141 connman_inet_set_address(origin->index, origin->address);
1144 void __connman_ipconfig_set_element_ipv6_gateway(
1145 struct connman_ipconfig *ipconfig,
1146 struct connman_element *element)
1148 if (ipconfig->type == CONNMAN_IPCONFIG_TYPE_IPV6)
1149 element->ipv6.gateway = ipconfig->address->gateway;
1153 * FIXME: The element soulution should be removed in the future
1154 * Set IPv4 and IPv6 gateway
1156 int __connman_ipconfig_set_gateway(struct connman_ipconfig *ipconfig,
1157 struct connman_element *parent)
1159 struct connman_element *connection;
1161 connection = connman_element_create(NULL);
1163 DBG("ipconfig %p", ipconfig);
1165 connection->type = CONNMAN_ELEMENT_TYPE_CONNECTION;
1166 connection->index = ipconfig->index;
1168 if (ipconfig->type == CONNMAN_IPCONFIG_TYPE_IPV4)
1169 connection->ipv4.gateway = ipconfig->address->gateway;
1170 else if (ipconfig->type == CONNMAN_IPCONFIG_TYPE_IPV6)
1171 connection->ipv6.gateway = ipconfig->address->gateway;
1173 if (connman_element_register(connection, parent) < 0)
1174 connman_element_unref(connection);
1179 int __connman_ipconfig_set_address(struct connman_ipconfig *ipconfig)
1183 switch (ipconfig->method) {
1184 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
1185 case CONNMAN_IPCONFIG_METHOD_OFF:
1186 case CONNMAN_IPCONFIG_METHOD_FIXED:
1187 case CONNMAN_IPCONFIG_METHOD_DHCP:
1188 case CONNMAN_IPCONFIG_METHOD_AUTO:
1190 case CONNMAN_IPCONFIG_METHOD_MANUAL:
1191 if (ipconfig->type == CONNMAN_IPCONFIG_TYPE_IPV4)
1192 return connman_inet_set_address(ipconfig->index,
1194 else if (ipconfig->type == CONNMAN_IPCONFIG_TYPE_IPV6)
1195 return connman_inet_set_ipv6_address(
1196 ipconfig->index, ipconfig->address);
1202 int __connman_ipconfig_clear_address(struct connman_ipconfig *ipconfig)
1206 if (ipconfig == NULL)
1209 DBG("method %d", ipconfig->method);
1211 switch (ipconfig->method) {
1212 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
1213 case CONNMAN_IPCONFIG_METHOD_OFF:
1214 case CONNMAN_IPCONFIG_METHOD_FIXED:
1215 case CONNMAN_IPCONFIG_METHOD_DHCP:
1216 case CONNMAN_IPCONFIG_METHOD_AUTO:
1218 case CONNMAN_IPCONFIG_METHOD_MANUAL:
1219 if (ipconfig->type == CONNMAN_IPCONFIG_TYPE_IPV4)
1220 return connman_inet_clear_address(ipconfig->index,
1222 else if (ipconfig->type == CONNMAN_IPCONFIG_TYPE_IPV6)
1223 return connman_inet_clear_ipv6_address(
1225 ipconfig->address->local,
1226 ipconfig->address->prefixlen);
1232 int __connman_ipconfig_set_proxy_autoconfig(struct connman_ipconfig *ipconfig,
1235 struct connman_ipdevice *ipdevice;
1237 DBG("ipconfig %p", ipconfig);
1239 if (ipconfig == NULL || ipconfig->index < 0)
1242 ipdevice = g_hash_table_lookup(ipdevice_hash,
1243 GINT_TO_POINTER(ipconfig->index));
1244 if (ipdevice == NULL)
1247 g_free(ipdevice->pac);
1248 ipdevice->pac = g_strdup(url);
1253 const char *__connman_ipconfig_get_proxy_autoconfig(struct connman_ipconfig *ipconfig)
1255 struct connman_ipdevice *ipdevice;
1257 DBG("ipconfig %p", ipconfig);
1259 if (ipconfig == NULL || ipconfig->index < 0)
1262 ipdevice = g_hash_table_lookup(ipdevice_hash,
1263 GINT_TO_POINTER(ipconfig->index));
1264 if (ipdevice == NULL)
1267 return ipdevice->pac;
1270 int __connman_ipconfig_enable(struct connman_ipconfig *ipconfig)
1272 struct connman_ipdevice *ipdevice;
1273 gboolean up = FALSE, down = FALSE;
1274 gboolean lower_up = FALSE, lower_down = FALSE;
1275 enum connman_ipconfig_type type;
1277 DBG("ipconfig %p", ipconfig);
1279 if (ipconfig == NULL || ipconfig->index < 0)
1282 ipdevice = g_hash_table_lookup(ipdevice_hash,
1283 GINT_TO_POINTER(ipconfig->index));
1284 if (ipdevice == NULL)
1287 if (ipconfig->type == CONNMAN_IPCONFIG_TYPE_IPV4) {
1288 if (ipdevice->config_ipv4 == ipconfig)
1290 type = CONNMAN_IPCONFIG_TYPE_IPV4;
1291 } else if (ipconfig->type == CONNMAN_IPCONFIG_TYPE_IPV6) {
1292 if (ipdevice->config_ipv6 == ipconfig)
1294 type = CONNMAN_IPCONFIG_TYPE_IPV6;
1298 if (type == CONNMAN_IPCONFIG_TYPE_IPV4 &&
1299 ipdevice->config_ipv4 != NULL) {
1300 ipconfig_list = g_list_remove(ipconfig_list,
1301 ipdevice->config_ipv4);
1303 connman_ipaddress_clear(ipdevice->config_ipv4->system);
1305 connman_ipconfig_unref(ipdevice->config_ipv4);
1308 if (type == CONNMAN_IPCONFIG_TYPE_IPV6 &&
1309 ipdevice->config_ipv6 != NULL) {
1310 ipconfig_list = g_list_remove(ipconfig_list,
1311 ipdevice->config_ipv6);
1313 connman_ipaddress_clear(ipdevice->config_ipv6->system);
1315 connman_ipconfig_unref(ipdevice->config_ipv6);
1318 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
1319 ipdevice->config_ipv4 = connman_ipconfig_ref(ipconfig);
1320 else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
1321 ipdevice->config_ipv6 = connman_ipconfig_ref(ipconfig);
1323 ipconfig_list = g_list_append(ipconfig_list, ipconfig);
1325 if (ipdevice->flags & IFF_UP)
1330 if ((ipdevice->flags & (IFF_RUNNING | IFF_LOWER_UP)) ==
1331 (IFF_RUNNING | IFF_LOWER_UP))
1333 else if ((ipdevice->flags & (IFF_RUNNING | IFF_LOWER_UP)) == 0)
1336 if (up == TRUE && ipconfig->ops->up)
1337 ipconfig->ops->up(ipconfig);
1338 if (lower_up == TRUE && ipconfig->ops->lower_up)
1339 ipconfig->ops->lower_up(ipconfig);
1341 if (lower_down == TRUE && ipconfig->ops->lower_down)
1342 ipconfig->ops->lower_down(ipconfig);
1343 if (down == TRUE && ipconfig->ops->down)
1344 ipconfig->ops->down(ipconfig);
1349 int __connman_ipconfig_disable(struct connman_ipconfig *ipconfig)
1351 struct connman_ipdevice *ipdevice;
1353 DBG("ipconfig %p", ipconfig);
1355 if (ipconfig == NULL || ipconfig->index < 0)
1358 ipdevice = g_hash_table_lookup(ipdevice_hash,
1359 GINT_TO_POINTER(ipconfig->index));
1360 if (ipdevice == NULL)
1363 if (ipdevice->config_ipv4 == NULL && ipdevice->config_ipv6 == NULL)
1366 if (ipdevice->config_ipv4 == ipconfig) {
1367 ipconfig_list = g_list_remove(ipconfig_list, ipconfig);
1369 connman_ipaddress_clear(ipdevice->config_ipv4->system);
1370 connman_ipconfig_unref(ipdevice->config_ipv4);
1371 ipdevice->config_ipv4 = NULL;
1375 if (ipdevice->config_ipv6 == ipconfig) {
1376 ipconfig_list = g_list_remove(ipconfig_list, ipconfig);
1378 connman_ipaddress_clear(ipdevice->config_ipv6->system);
1379 connman_ipconfig_unref(ipdevice->config_ipv6);
1380 ipdevice->config_ipv6 = NULL;
1387 const char *__connman_ipconfig_method2string(enum connman_ipconfig_method method)
1390 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
1392 case CONNMAN_IPCONFIG_METHOD_OFF:
1394 case CONNMAN_IPCONFIG_METHOD_FIXED:
1396 case CONNMAN_IPCONFIG_METHOD_MANUAL:
1398 case CONNMAN_IPCONFIG_METHOD_DHCP:
1400 case CONNMAN_IPCONFIG_METHOD_AUTO:
1407 enum connman_ipconfig_method __connman_ipconfig_string2method(const char *method)
1409 if (g_strcmp0(method, "off") == 0)
1410 return CONNMAN_IPCONFIG_METHOD_OFF;
1411 else if (g_strcmp0(method, "fixed") == 0)
1412 return CONNMAN_IPCONFIG_METHOD_FIXED;
1413 else if (g_strcmp0(method, "manual") == 0)
1414 return CONNMAN_IPCONFIG_METHOD_MANUAL;
1415 else if (g_strcmp0(method, "dhcp") == 0)
1416 return CONNMAN_IPCONFIG_METHOD_DHCP;
1417 else if (g_strcmp0(method, "auto") == 0)
1418 return CONNMAN_IPCONFIG_METHOD_AUTO;
1420 return CONNMAN_IPCONFIG_METHOD_UNKNOWN;
1423 void __connman_ipconfig_append_ipv4(struct connman_ipconfig *ipconfig,
1424 DBusMessageIter *iter)
1430 if (ipconfig->type != CONNMAN_IPCONFIG_TYPE_IPV4)
1433 str = __connman_ipconfig_method2string(ipconfig->method);
1437 connman_dbus_dict_append_basic(iter, "Method", DBUS_TYPE_STRING, &str);
1439 if (ipconfig->system == NULL)
1442 if (ipconfig->system->local != NULL) {
1444 struct in_addr netmask;
1447 connman_dbus_dict_append_basic(iter, "Address",
1448 DBUS_TYPE_STRING, &ipconfig->system->local);
1450 addr = 0xffffffff << (32 - ipconfig->system->prefixlen);
1451 netmask.s_addr = htonl(addr);
1452 mask = inet_ntoa(netmask);
1453 connman_dbus_dict_append_basic(iter, "Netmask",
1454 DBUS_TYPE_STRING, &mask);
1457 if (ipconfig->system->gateway != NULL)
1458 connman_dbus_dict_append_basic(iter, "Gateway",
1459 DBUS_TYPE_STRING, &ipconfig->system->gateway);
1462 void __connman_ipconfig_append_ipv6(struct connman_ipconfig *ipconfig,
1463 DBusMessageIter *iter)
1469 if (ipconfig->type != CONNMAN_IPCONFIG_TYPE_IPV6)
1472 str = __connman_ipconfig_method2string(ipconfig->method);
1476 connman_dbus_dict_append_basic(iter, "Method", DBUS_TYPE_STRING, &str);
1478 if (ipconfig->system == NULL)
1481 if (ipconfig->system->local != NULL) {
1482 connman_dbus_dict_append_basic(iter, "Address",
1483 DBUS_TYPE_STRING, &ipconfig->system->local);
1484 connman_dbus_dict_append_basic(iter, "PrefixLength",
1486 &ipconfig->system->prefixlen);
1489 if (ipconfig->system->gateway != NULL)
1490 connman_dbus_dict_append_basic(iter, "Gateway",
1491 DBUS_TYPE_STRING, &ipconfig->system->gateway);
1494 void __connman_ipconfig_append_ipv6config(struct connman_ipconfig *ipconfig,
1495 DBusMessageIter *iter)
1501 str = __connman_ipconfig_method2string(ipconfig->method);
1505 connman_dbus_dict_append_basic(iter, "Method", DBUS_TYPE_STRING, &str);
1507 switch (ipconfig->method) {
1508 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
1509 case CONNMAN_IPCONFIG_METHOD_OFF:
1510 case CONNMAN_IPCONFIG_METHOD_DHCP:
1512 case CONNMAN_IPCONFIG_METHOD_FIXED:
1513 case CONNMAN_IPCONFIG_METHOD_MANUAL:
1514 case CONNMAN_IPCONFIG_METHOD_AUTO:
1518 if (ipconfig->address == NULL)
1521 if (ipconfig->address->local != NULL) {
1522 connman_dbus_dict_append_basic(iter, "Address",
1523 DBUS_TYPE_STRING, &ipconfig->address->local);
1524 connman_dbus_dict_append_basic(iter, "PrefixLength",
1526 &ipconfig->address->prefixlen);
1529 if (ipconfig->address->gateway != NULL)
1530 connman_dbus_dict_append_basic(iter, "Gateway",
1531 DBUS_TYPE_STRING, &ipconfig->address->gateway);
1534 void __connman_ipconfig_append_ipv4config(struct connman_ipconfig *ipconfig,
1535 DBusMessageIter *iter)
1541 str = __connman_ipconfig_method2string(ipconfig->method);
1545 connman_dbus_dict_append_basic(iter, "Method", DBUS_TYPE_STRING, &str);
1547 switch (ipconfig->method) {
1548 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
1549 case CONNMAN_IPCONFIG_METHOD_OFF:
1550 case CONNMAN_IPCONFIG_METHOD_FIXED:
1551 case CONNMAN_IPCONFIG_METHOD_DHCP:
1552 case CONNMAN_IPCONFIG_METHOD_AUTO:
1554 case CONNMAN_IPCONFIG_METHOD_MANUAL:
1558 if (ipconfig->address == NULL)
1561 if (ipconfig->address->local != NULL) {
1563 struct in_addr netmask;
1566 connman_dbus_dict_append_basic(iter, "Address",
1567 DBUS_TYPE_STRING, &ipconfig->address->local);
1569 addr = 0xffffffff << (32 - ipconfig->address->prefixlen);
1570 netmask.s_addr = htonl(addr);
1571 mask = inet_ntoa(netmask);
1572 connman_dbus_dict_append_basic(iter, "Netmask",
1573 DBUS_TYPE_STRING, &mask);
1576 if (ipconfig->address->gateway != NULL)
1577 connman_dbus_dict_append_basic(iter, "Gateway",
1578 DBUS_TYPE_STRING, &ipconfig->address->gateway);
1581 static void disable_ipv6(struct connman_ipconfig *ipconfig)
1583 struct connman_ipdevice *ipdevice;
1587 ipdevice = g_hash_table_lookup(ipdevice_hash,
1588 GINT_TO_POINTER(ipconfig->index));
1589 if (ipdevice == NULL)
1592 set_ipv6_state(ipdevice->ifname, FALSE);
1595 static void enable_ipv6(struct connman_ipconfig *ipconfig)
1597 struct connman_ipdevice *ipdevice;
1601 ipdevice = g_hash_table_lookup(ipdevice_hash,
1602 GINT_TO_POINTER(ipconfig->index));
1603 if (ipdevice == NULL)
1606 set_ipv6_state(ipdevice->ifname, TRUE);
1609 int __connman_ipconfig_set_config(struct connman_ipconfig *ipconfig,
1610 DBusMessageIter *array)
1612 enum connman_ipconfig_method method = CONNMAN_IPCONFIG_METHOD_UNKNOWN;
1613 const char *address = NULL, *netmask = NULL, *gateway = NULL,
1614 *prefix_length_string = NULL;
1615 int prefix_length = 0;
1616 DBusMessageIter dict;
1618 DBG("ipconfig %p", ipconfig);
1620 if (dbus_message_iter_get_arg_type(array) != DBUS_TYPE_ARRAY)
1623 dbus_message_iter_recurse(array, &dict);
1625 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
1626 DBusMessageIter entry;
1630 dbus_message_iter_recurse(&dict, &entry);
1632 if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING)
1635 dbus_message_iter_get_basic(&entry, &key);
1636 dbus_message_iter_next(&entry);
1638 type = dbus_message_iter_get_arg_type(&entry);
1640 if (g_str_equal(key, "Method") == TRUE) {
1643 if (type != DBUS_TYPE_STRING)
1646 dbus_message_iter_get_basic(&entry, &str);
1647 method = __connman_ipconfig_string2method(str);
1648 } else if (g_str_equal(key, "Address") == TRUE) {
1649 if (type != DBUS_TYPE_STRING)
1652 dbus_message_iter_get_basic(&entry, &address);
1653 } else if (g_str_equal(key, "PrefixLength") == TRUE) {
1654 if (type != DBUS_TYPE_STRING)
1657 dbus_message_iter_get_basic(&entry,
1658 &prefix_length_string);
1660 prefix_length = atoi(prefix_length_string);
1661 if (prefix_length < 0 || prefix_length > 128)
1664 } else if (g_str_equal(key, "Netmask") == TRUE) {
1665 if (type != DBUS_TYPE_STRING)
1668 dbus_message_iter_get_basic(&entry, &netmask);
1669 } else if (g_str_equal(key, "Gateway") == TRUE) {
1670 if (type != DBUS_TYPE_STRING)
1673 dbus_message_iter_get_basic(&entry, &gateway);
1675 dbus_message_iter_next(&dict);
1678 DBG("method %d address %s netmask %s gateway %s prefix_length %d",
1679 method, address, netmask, gateway, prefix_length);
1682 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
1683 case CONNMAN_IPCONFIG_METHOD_FIXED:
1686 case CONNMAN_IPCONFIG_METHOD_OFF:
1687 ipconfig->method = method;
1688 if (ipconfig->type == CONNMAN_IPCONFIG_TYPE_IPV6)
1689 disable_ipv6(ipconfig);
1692 case CONNMAN_IPCONFIG_METHOD_AUTO:
1693 if (ipconfig->type != CONNMAN_IPCONFIG_TYPE_IPV6)
1696 ipconfig->method = method;
1697 enable_ipv6(ipconfig);
1700 case CONNMAN_IPCONFIG_METHOD_MANUAL:
1701 if (address == NULL)
1704 ipconfig->method = method;
1706 if (ipconfig->type == CONNMAN_IPCONFIG_TYPE_IPV4)
1707 connman_ipaddress_set_ipv4(ipconfig->address,
1708 address, netmask, gateway);
1710 return connman_ipaddress_set_ipv6(
1711 ipconfig->address, address,
1712 gateway, prefix_length);
1715 case CONNMAN_IPCONFIG_METHOD_DHCP:
1716 if (ipconfig->type == CONNMAN_IPCONFIG_TYPE_IPV6)
1719 ipconfig->method = method;
1726 void __connman_ipconfig_append_ethernet(struct connman_ipconfig *ipconfig,
1727 DBusMessageIter *iter)
1729 struct connman_ipdevice *ipdevice;
1730 const char *method = "auto";
1732 connman_dbus_dict_append_basic(iter, "Method",
1733 DBUS_TYPE_STRING, &method);
1735 ipdevice = g_hash_table_lookup(ipdevice_hash,
1736 GINT_TO_POINTER(ipconfig->index));
1737 if (ipdevice == NULL)
1740 if (ipdevice->ifname != NULL)
1741 connman_dbus_dict_append_basic(iter, "Interface",
1742 DBUS_TYPE_STRING, &ipdevice->ifname);
1744 if (ipdevice->address != NULL)
1745 connman_dbus_dict_append_basic(iter, "Address",
1746 DBUS_TYPE_STRING, &ipdevice->address);
1748 if (ipdevice->mtu > 0)
1749 connman_dbus_dict_append_basic(iter, "MTU",
1750 DBUS_TYPE_UINT16, &ipdevice->mtu);
1753 int __connman_ipconfig_load(struct connman_ipconfig *ipconfig,
1754 GKeyFile *keyfile, const char *identifier, const char *prefix)
1759 DBG("ipconfig %p identifier %s", ipconfig, identifier);
1761 key = g_strdup_printf("%smethod", prefix);
1762 method = g_key_file_get_string(keyfile, identifier, key, NULL);
1763 if (method == NULL) {
1764 if (ipconfig->type == CONNMAN_IPCONFIG_TYPE_IPV4)
1765 ipconfig->method = CONNMAN_IPCONFIG_METHOD_DHCP;
1767 ipconfig->method = CONNMAN_IPCONFIG_METHOD_OFF;
1769 ipconfig->method = __connman_ipconfig_string2method(method);
1771 if (ipconfig->method == CONNMAN_IPCONFIG_METHOD_UNKNOWN)
1772 ipconfig->method = CONNMAN_IPCONFIG_METHOD_OFF;
1777 key = g_strdup_printf("%snetmask_prefixlen", prefix);
1778 ipconfig->address->prefixlen = g_key_file_get_integer(
1779 keyfile, identifier, key, NULL);
1782 key = g_strdup_printf("%slocal_address", prefix);
1783 ipconfig->address->local = g_key_file_get_string(
1784 keyfile, identifier, key, NULL);
1787 key = g_strdup_printf("%speer_address", prefix);
1788 ipconfig->address->peer = g_key_file_get_string(
1789 keyfile, identifier, key, NULL);
1792 key = g_strdup_printf("%sbroadcast_address", prefix);
1793 ipconfig->address->broadcast = g_key_file_get_string(
1794 keyfile, identifier, key, NULL);
1797 key = g_strdup_printf("%sgateway", prefix);
1798 ipconfig->address->gateway = g_key_file_get_string(
1799 keyfile, identifier, key, NULL);
1805 int __connman_ipconfig_save(struct connman_ipconfig *ipconfig,
1806 GKeyFile *keyfile, const char *identifier, const char *prefix)
1811 DBG("ipconfig %p identifier %s", ipconfig, identifier);
1813 method = __connman_ipconfig_method2string(ipconfig->method);
1815 key = g_strdup_printf("%smethod", prefix);
1816 g_key_file_set_string(keyfile, identifier, key, method);
1819 key = g_strdup_printf("%snetmask_prefixlen", prefix);
1820 g_key_file_set_integer(keyfile, identifier,
1821 key, ipconfig->address->prefixlen);
1824 key = g_strdup_printf("%slocal_address", prefix);
1825 if (ipconfig->address->local != NULL)
1826 g_key_file_set_string(keyfile, identifier,
1827 key, ipconfig->address->local);
1830 key = g_strdup_printf("%speer_address", prefix);
1831 if (ipconfig->address->peer != NULL)
1832 g_key_file_set_string(keyfile, identifier,
1833 key, ipconfig->address->peer);
1836 key = g_strdup_printf("%sbroadcast_address", prefix);
1837 if (ipconfig->address->broadcast != NULL)
1838 g_key_file_set_string(keyfile, identifier,
1839 key, ipconfig->address->broadcast);
1842 key = g_strdup_printf("%sgateway", prefix);
1843 if (ipconfig->address->gateway != NULL)
1844 g_key_file_set_string(keyfile, identifier,
1845 key, ipconfig->address->gateway);
1851 int __connman_ipconfig_init(void)
1855 ipdevice_hash = g_hash_table_new_full(g_direct_hash, g_direct_equal,
1856 NULL, free_ipdevice);
1861 void __connman_ipconfig_cleanup(void)
1865 g_hash_table_destroy(ipdevice_hash);
1866 ipdevice_hash = NULL;