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;
82 static GHashTable *ipdevice_hash = NULL;
83 static GList *ipconfig_list = NULL;
85 struct connman_ipaddress *connman_ipaddress_alloc(int family)
87 struct connman_ipaddress *ipaddress;
89 ipaddress = g_try_new0(struct connman_ipaddress, 1);
90 if (ipaddress == NULL)
93 ipaddress->family = family;
94 ipaddress->prefixlen = 0;
95 ipaddress->local = NULL;
96 ipaddress->peer = NULL;
97 ipaddress->broadcast = NULL;
98 ipaddress->gateway = NULL;
103 void connman_ipaddress_free(struct connman_ipaddress *ipaddress)
105 if (ipaddress == NULL)
108 g_free(ipaddress->broadcast);
109 g_free(ipaddress->peer);
110 g_free(ipaddress->local);
111 g_free(ipaddress->gateway);
115 unsigned char __connman_ipconfig_netmask_prefix_len(const char *netmask)
124 mask = inet_network(netmask);
127 /* a valid netmask must be 2^n - 1 */
128 if ((host & (host + 1)) != 0)
132 for (; mask; mask <<= 1)
138 static gboolean check_ipv6_address(const char *address)
140 unsigned char buf[sizeof(struct in6_addr)];
143 err = inet_pton(AF_INET6, address, buf);
150 int connman_ipaddress_set_ipv6(struct connman_ipaddress *ipaddress,
151 const char *address, const char *gateway,
152 unsigned char prefix_length)
154 if (ipaddress == NULL)
157 if (check_ipv6_address(address) == FALSE)
160 if (check_ipv6_address(gateway) == FALSE)
163 DBG("prefix_len %d address %s gateway %s",
164 prefix_length, address, gateway);
166 ipaddress->prefixlen = prefix_length;
168 g_free(ipaddress->local);
169 ipaddress->local = g_strdup(address);
171 g_free(ipaddress->gateway);
172 ipaddress->gateway = g_strdup(gateway);
177 void connman_ipaddress_set_ipv4(struct connman_ipaddress *ipaddress,
178 const char *address, const char *netmask, const char *gateway)
180 if (ipaddress == NULL)
183 ipaddress->prefixlen = __connman_ipconfig_netmask_prefix_len(netmask);
185 g_free(ipaddress->local);
186 ipaddress->local = g_strdup(address);
188 g_free(ipaddress->gateway);
189 ipaddress->gateway = g_strdup(gateway);
192 void connman_ipaddress_clear(struct connman_ipaddress *ipaddress)
194 if (ipaddress == NULL)
197 ipaddress->prefixlen = 0;
199 g_free(ipaddress->local);
200 ipaddress->local = NULL;
202 g_free(ipaddress->peer);
203 ipaddress->peer = NULL;
205 g_free(ipaddress->broadcast);
206 ipaddress->broadcast = NULL;
208 g_free(ipaddress->gateway);
209 ipaddress->gateway = NULL;
212 void connman_ipaddress_copy(struct connman_ipaddress *ipaddress,
213 struct connman_ipaddress *source)
215 if (ipaddress == NULL || source == NULL)
218 ipaddress->family = source->family;
219 ipaddress->prefixlen = source->prefixlen;
221 g_free(ipaddress->local);
222 ipaddress->local = g_strdup(source->local);
224 g_free(ipaddress->peer);
225 ipaddress->peer = g_strdup(source->peer);
227 g_free(ipaddress->broadcast);
228 ipaddress->broadcast = g_strdup(source->broadcast);
230 g_free(ipaddress->gateway);
231 ipaddress->gateway = g_strdup(source->gateway);
234 static void free_address_list(struct connman_ipdevice *ipdevice)
238 for (list = ipdevice->address_list; list; list = list->next) {
239 struct connman_ipaddress *ipaddress = list->data;
241 connman_ipaddress_free(ipaddress);
245 g_slist_free(ipdevice->address_list);
246 ipdevice->address_list = NULL;
249 static struct connman_ipaddress *find_ipaddress(struct connman_ipdevice *ipdevice,
250 unsigned char prefixlen, const char *local)
254 for (list = ipdevice->address_list; list; list = list->next) {
255 struct connman_ipaddress *ipaddress = list->data;
257 if (g_strcmp0(ipaddress->local, local) == 0 &&
258 ipaddress->prefixlen == prefixlen)
265 static const char *type2str(unsigned short type)
270 case ARPHRD_LOOPBACK:
283 static const char *scope2str(unsigned char scope)
295 static void set_ipv6_state(gchar *ifname, gboolean enable)
301 path = g_strdup("/proc/sys/net/ipv6/conf/all/disable_ipv6");
303 path = g_strdup_printf(
304 "/proc/sys/net/ipv6/conf/%s/disable_ipv6", ifname);
309 f = fopen(path, "r+");
324 static void free_ipdevice(gpointer data)
326 struct connman_ipdevice *ipdevice = data;
328 connman_info("%s {remove} index %d", ipdevice->ifname,
331 if (ipdevice->config_ipv4 != NULL) {
332 connman_ipconfig_unref(ipdevice->config_ipv4);
333 ipdevice->config_ipv4 = NULL;
336 if (ipdevice->config_ipv6 != NULL) {
337 connman_ipconfig_unref(ipdevice->config_ipv6);
338 ipdevice->config_ipv6 = NULL;
341 free_address_list(ipdevice);
342 g_free(ipdevice->ipv4_gateway);
343 g_free(ipdevice->ipv6_gateway);
344 g_free(ipdevice->pac);
346 g_free(ipdevice->address);
347 g_free(ipdevice->ifname);
351 static void __connman_ipconfig_lower_up(struct connman_ipdevice *ipdevice)
353 DBG("ipconfig ipv4 %p ipv6 %p", ipdevice->config_ipv4,
354 ipdevice->config_ipv6);
357 static void __connman_ipconfig_lower_down(struct connman_ipdevice *ipdevice)
359 DBG("ipconfig ipv4 %p ipv6 %p", ipdevice->config_ipv4,
360 ipdevice->config_ipv6);
362 if (ipdevice->config_ipv4)
363 connman_inet_clear_address(ipdevice->index,
364 ipdevice->config_ipv4->address);
366 if (ipdevice->config_ipv6)
367 connman_inet_clear_ipv6_address(ipdevice->index,
368 ipdevice->config_ipv6->address->local,
369 ipdevice->config_ipv6->address->prefixlen);
372 static void update_stats(struct connman_ipdevice *ipdevice,
373 struct rtnl_link_stats *stats)
375 struct connman_service *service;
377 if (stats->rx_packets == 0 && stats->tx_packets == 0)
380 connman_info("%s {RX} %u packets %u bytes", ipdevice->ifname,
381 stats->rx_packets, stats->rx_bytes);
382 connman_info("%s {TX} %u packets %u bytes", ipdevice->ifname,
383 stats->tx_packets, stats->tx_bytes);
385 if (ipdevice->config_ipv4 == NULL && ipdevice->config_ipv6 == NULL)
388 if (ipdevice->config_ipv4)
389 service = connman_ipconfig_get_data(ipdevice->config_ipv4);
390 else if (ipdevice->config_ipv6)
391 service = connman_ipconfig_get_data(ipdevice->config_ipv6);
398 ipdevice->rx_packets = stats->rx_packets;
399 ipdevice->tx_packets = stats->tx_packets;
400 ipdevice->rx_bytes = stats->rx_bytes;
401 ipdevice->tx_bytes = stats->tx_bytes;
402 ipdevice->rx_errors = stats->rx_errors;
403 ipdevice->tx_errors = stats->tx_errors;
404 ipdevice->rx_dropped = stats->rx_dropped;
405 ipdevice->tx_dropped = stats->tx_dropped;
407 __connman_service_notify(service,
408 ipdevice->rx_packets, ipdevice->tx_packets,
409 ipdevice->rx_bytes, ipdevice->tx_bytes,
410 ipdevice->rx_errors, ipdevice->tx_errors,
411 ipdevice->rx_dropped, ipdevice->tx_dropped);
414 void __connman_ipconfig_newlink(int index, unsigned short type,
415 unsigned int flags, const char *address,
417 struct rtnl_link_stats *stats)
419 struct connman_ipdevice *ipdevice;
422 gboolean up = FALSE, down = FALSE;
423 gboolean lower_up = FALSE, lower_down = FALSE;
425 DBG("index %d", index);
427 if (type == ARPHRD_LOOPBACK)
430 ipdevice = g_hash_table_lookup(ipdevice_hash, GINT_TO_POINTER(index));
431 if (ipdevice != NULL)
434 ipdevice = g_try_new0(struct connman_ipdevice, 1);
435 if (ipdevice == NULL)
438 ipdevice->index = index;
439 ipdevice->ifname = connman_inet_ifname(index);
440 ipdevice->type = type;
442 ipdevice->address = g_strdup(address);
444 g_hash_table_insert(ipdevice_hash, GINT_TO_POINTER(index), ipdevice);
446 connman_info("%s {create} index %d type %d <%s>", ipdevice->ifname,
447 index, type, type2str(type));
452 update_stats(ipdevice, stats);
454 if (flags == ipdevice->flags)
457 if ((ipdevice->flags & IFF_UP) != (flags & IFF_UP)) {
464 if ((ipdevice->flags & (IFF_RUNNING | IFF_LOWER_UP)) !=
465 (flags & (IFF_RUNNING | IFF_LOWER_UP))) {
466 if ((flags & (IFF_RUNNING | IFF_LOWER_UP)) ==
467 (IFF_RUNNING | IFF_LOWER_UP))
469 else if ((flags & (IFF_RUNNING | IFF_LOWER_UP)) == 0)
473 ipdevice->flags = flags;
475 str = g_string_new(NULL);
480 g_string_append(str, "UP");
482 g_string_append(str, "DOWN");
484 if (flags & IFF_RUNNING)
485 g_string_append(str, ",RUNNING");
487 if (flags & IFF_LOWER_UP)
488 g_string_append(str, ",LOWER_UP");
490 connman_info("%s {update} flags %u <%s>", ipdevice->ifname,
493 g_string_free(str, TRUE);
495 for (list = g_list_first(ipconfig_list); list;
496 list = g_list_next(list)) {
497 struct connman_ipconfig *ipconfig = list->data;
499 if (index != ipconfig->index)
502 if (ipconfig->ops == NULL)
505 if (up == TRUE && ipconfig->ops->up)
506 ipconfig->ops->up(ipconfig);
507 if (lower_up == TRUE && ipconfig->ops->lower_up)
508 ipconfig->ops->lower_up(ipconfig);
510 if (lower_down == TRUE && ipconfig->ops->lower_down)
511 ipconfig->ops->lower_down(ipconfig);
512 if (down == TRUE && ipconfig->ops->down)
513 ipconfig->ops->down(ipconfig);
517 __connman_ipconfig_lower_up(ipdevice);
519 __connman_ipconfig_lower_down(ipdevice);
522 void __connman_ipconfig_dellink(int index, struct rtnl_link_stats *stats)
524 struct connman_ipdevice *ipdevice;
527 DBG("index %d", index);
529 ipdevice = g_hash_table_lookup(ipdevice_hash, GINT_TO_POINTER(index));
530 if (ipdevice == NULL)
533 update_stats(ipdevice, stats);
535 for (list = g_list_first(ipconfig_list); list;
536 list = g_list_next(list)) {
537 struct connman_ipconfig *ipconfig = list->data;
539 if (index != ipconfig->index)
542 ipconfig->index = -1;
544 if (ipconfig->ops == NULL)
547 if (ipconfig->ops->lower_down)
548 ipconfig->ops->lower_down(ipconfig);
549 if (ipconfig->ops->down)
550 ipconfig->ops->down(ipconfig);
553 __connman_ipconfig_lower_down(ipdevice);
555 g_hash_table_remove(ipdevice_hash, GINT_TO_POINTER(index));
558 static inline gint check_duplicate_address(gconstpointer a, gconstpointer b)
560 const struct connman_ipaddress *addr1 = a;
561 const struct connman_ipaddress *addr2 = b;
563 if (addr1->prefixlen != addr2->prefixlen)
564 return addr2->prefixlen - addr1->prefixlen;
566 return g_strcmp0(addr1->local, addr2->local);
569 void __connman_ipconfig_newaddr(int index, int family, const char *label,
570 unsigned char prefixlen, const char *address)
572 struct connman_ipdevice *ipdevice;
573 struct connman_ipaddress *ipaddress;
576 DBG("index %d", index);
578 ipdevice = g_hash_table_lookup(ipdevice_hash, GINT_TO_POINTER(index));
579 if (ipdevice == NULL)
582 ipaddress = connman_ipaddress_alloc(family);
583 if (ipaddress == NULL)
586 ipaddress->prefixlen = prefixlen;
587 ipaddress->local = g_strdup(address);
589 if (g_slist_find_custom(ipdevice->address_list, ipaddress,
590 check_duplicate_address)) {
591 connman_ipaddress_free(ipaddress);
595 ipdevice->address_list = g_slist_append(ipdevice->address_list,
598 connman_info("%s {add} address %s/%u label %s family %d",
599 ipdevice->ifname, address, prefixlen, label, family);
601 if (ipdevice->config_ipv4 != NULL && family == AF_INET)
602 connman_ipaddress_copy(ipdevice->config_ipv4->system,
605 else if (ipdevice->config_ipv6 != NULL && family == AF_INET6)
606 connman_ipaddress_copy(ipdevice->config_ipv6->system,
611 if ((ipdevice->flags & (IFF_RUNNING | IFF_LOWER_UP)) != (IFF_RUNNING | IFF_LOWER_UP))
614 for (list = g_list_first(ipconfig_list); list;
615 list = g_list_next(list)) {
616 struct connman_ipconfig *ipconfig = list->data;
618 if (index != ipconfig->index)
621 if (ipconfig->ops == NULL)
624 if (ipconfig->ops->ip_bound)
625 ipconfig->ops->ip_bound(ipconfig);
629 void __connman_ipconfig_deladdr(int index, int family, const char *label,
630 unsigned char prefixlen, const char *address)
632 struct connman_ipdevice *ipdevice;
633 struct connman_ipaddress *ipaddress;
636 DBG("index %d", index);
638 ipdevice = g_hash_table_lookup(ipdevice_hash, GINT_TO_POINTER(index));
639 if (ipdevice == NULL)
642 ipaddress = find_ipaddress(ipdevice, prefixlen, address);
643 if (ipaddress == NULL)
646 ipdevice->address_list = g_slist_remove(ipdevice->address_list,
649 connman_ipaddress_free(ipaddress);
651 connman_info("%s {del} address %s/%u label %s", ipdevice->ifname,
652 address, prefixlen, label);
654 if ((ipdevice->flags & (IFF_RUNNING | IFF_LOWER_UP)) != (IFF_RUNNING | IFF_LOWER_UP))
657 if (g_slist_length(ipdevice->address_list) > 0)
660 for (list = g_list_first(ipconfig_list); list;
661 list = g_list_next(list)) {
662 struct connman_ipconfig *ipconfig = list->data;
664 if (index != ipconfig->index)
667 if (ipconfig->ops == NULL)
670 if (ipconfig->ops->ip_release)
671 ipconfig->ops->ip_release(ipconfig);
675 void __connman_ipconfig_newroute(int index, int family, unsigned char scope,
676 const char *dst, const char *gateway)
678 struct connman_ipdevice *ipdevice;
680 DBG("index %d", index);
682 ipdevice = g_hash_table_lookup(ipdevice_hash, GINT_TO_POINTER(index));
683 if (ipdevice == NULL)
686 if (scope == 0 && g_strcmp0(dst, "0.0.0.0") == 0) {
690 if (family == AF_INET6) {
691 g_free(ipdevice->ipv6_gateway);
692 ipdevice->ipv6_gateway = g_strdup(gateway);
694 if (ipdevice->config_ipv6 != NULL &&
695 ipdevice->config_ipv6->system != NULL) {
696 g_free(ipdevice->config_ipv6->system->gateway);
697 ipdevice->config_ipv6->system->gateway =
701 g_free(ipdevice->ipv4_gateway);
702 ipdevice->ipv4_gateway = g_strdup(gateway);
704 if (ipdevice->config_ipv4 != NULL &&
705 ipdevice->config_ipv4->system != NULL) {
706 g_free(ipdevice->config_ipv4->system->gateway);
707 ipdevice->config_ipv4->system->gateway =
712 for (list = ipdevice->address_list; list; list = list->next) {
713 struct connman_ipaddress *ipaddress = list->data;
715 g_free(ipaddress->gateway);
716 ipaddress->gateway = g_strdup(gateway);
719 for (config_list = g_list_first(ipconfig_list); config_list;
720 config_list = g_list_next(config_list)) {
721 struct connman_ipconfig *ipconfig = config_list->data;
723 if (index != ipconfig->index)
726 if (ipconfig->ops == NULL)
729 if (ipconfig->ops->ip_bound)
730 ipconfig->ops->ip_bound(ipconfig);
734 connman_info("%s {add} route %s gw %s scope %u <%s>",
735 ipdevice->ifname, dst, gateway,
736 scope, scope2str(scope));
739 void __connman_ipconfig_delroute(int index, int family, unsigned char scope,
740 const char *dst, const char *gateway)
742 struct connman_ipdevice *ipdevice;
744 DBG("index %d", index);
746 ipdevice = g_hash_table_lookup(ipdevice_hash, GINT_TO_POINTER(index));
747 if (ipdevice == NULL)
750 if (scope == 0 && g_strcmp0(dst, "0.0.0.0") == 0) {
754 if (family == AF_INET6) {
755 g_free(ipdevice->ipv6_gateway);
756 ipdevice->ipv6_gateway = NULL;
758 if (ipdevice->config_ipv6 != NULL &&
759 ipdevice->config_ipv6->system != NULL) {
760 g_free(ipdevice->config_ipv6->system->gateway);
761 ipdevice->config_ipv6->system->gateway = NULL;
764 g_free(ipdevice->ipv4_gateway);
765 ipdevice->ipv4_gateway = NULL;
767 if (ipdevice->config_ipv4 != NULL &&
768 ipdevice->config_ipv4->system != NULL) {
769 g_free(ipdevice->config_ipv4->system->gateway);
770 ipdevice->config_ipv4->system->gateway = NULL;
774 for (list = ipdevice->address_list; list; list = list->next) {
775 struct connman_ipaddress *ipaddress = list->data;
777 g_free(ipaddress->gateway);
778 ipaddress->gateway = NULL;
781 for (config_list = g_list_first(ipconfig_list); config_list;
782 config_list = g_list_next(config_list)) {
783 struct connman_ipconfig *ipconfig = config_list->data;
785 if (index != ipconfig->index)
788 if (ipconfig->ops == NULL)
791 if (ipconfig->ops->ip_release)
792 ipconfig->ops->ip_release(ipconfig);
796 connman_info("%s {del} route %s gw %s scope %u <%s>",
797 ipdevice->ifname, dst, gateway,
798 scope, scope2str(scope));
801 void __connman_ipconfig_foreach(void (*function) (int index, void *user_data),
806 keys = g_hash_table_get_keys(ipdevice_hash);
810 for (list = g_list_first(keys); list; list = g_list_next(list)) {
811 int index = GPOINTER_TO_INT(list->data);
813 function(index, user_data);
819 unsigned short __connman_ipconfig_get_type(int index)
821 struct connman_ipdevice *ipdevice;
823 ipdevice = g_hash_table_lookup(ipdevice_hash, GINT_TO_POINTER(index));
824 if (ipdevice == NULL)
827 return ipdevice->type;
830 unsigned int __connman_ipconfig_get_flags(int index)
832 struct connman_ipdevice *ipdevice;
834 ipdevice = g_hash_table_lookup(ipdevice_hash, GINT_TO_POINTER(index));
835 if (ipdevice == NULL)
838 return ipdevice->flags;
841 const char *__connman_ipconfig_get_gateway(int index)
843 struct connman_ipdevice *ipdevice;
845 ipdevice = g_hash_table_lookup(ipdevice_hash, GINT_TO_POINTER(index));
846 if (ipdevice == NULL)
849 if (ipdevice->ipv4_gateway != NULL)
850 return ipdevice->ipv4_gateway;
852 if (ipdevice->config_ipv4 != NULL &&
853 ipdevice->config_ipv4->address != NULL)
854 return ipdevice->config_ipv4->address->gateway;
856 if (ipdevice->ipv6_gateway != NULL)
857 return ipdevice->ipv6_gateway;
859 if (ipdevice->config_ipv6 != NULL &&
860 ipdevice->config_ipv6->address != NULL)
861 return ipdevice->config_ipv6->address->gateway;
866 void __connman_ipconfig_set_index(struct connman_ipconfig *ipconfig, int index)
868 ipconfig->index = index;
871 static struct connman_ipconfig *create_ipv6config(int index)
873 struct connman_ipconfig *ipv6config;
875 DBG("index %d", index);
877 ipv6config = g_try_new0(struct connman_ipconfig, 1);
878 if (ipv6config == NULL)
881 ipv6config->refcount = 1;
883 ipv6config->index = index;
884 ipv6config->type = CONNMAN_IPCONFIG_TYPE_IPV6;
885 ipv6config->method = CONNMAN_IPCONFIG_METHOD_AUTO;
887 ipv6config->address = connman_ipaddress_alloc(AF_INET6);
888 if (ipv6config->address == NULL) {
893 ipv6config->system = connman_ipaddress_alloc(AF_INET6);
895 DBG("ipconfig %p", ipv6config);
901 * connman_ipconfig_create:
903 * Allocate a new ipconfig structure.
905 * Returns: a newly-allocated #connman_ipconfig structure
907 struct connman_ipconfig *connman_ipconfig_create(int index,
908 enum connman_ipconfig_type type)
910 struct connman_ipconfig *ipconfig;
912 if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
913 return create_ipv6config(index);
915 DBG("index %d", index);
917 ipconfig = g_try_new0(struct connman_ipconfig, 1);
918 if (ipconfig == NULL)
921 ipconfig->refcount = 1;
923 ipconfig->index = index;
924 ipconfig->type = CONNMAN_IPCONFIG_TYPE_IPV4;
926 ipconfig->address = connman_ipaddress_alloc(AF_INET);
927 if (ipconfig->address == NULL) {
932 ipconfig->system = connman_ipaddress_alloc(AF_INET);
934 DBG("ipconfig %p", ipconfig);
941 * connman_ipconfig_ref:
942 * @ipconfig: ipconfig structure
944 * Increase reference counter of ipconfig
946 struct connman_ipconfig *connman_ipconfig_ref(struct connman_ipconfig *ipconfig)
948 DBG("ipconfig %p refcount %d", ipconfig,
949 g_atomic_int_get(&ipconfig->refcount) + 1);
951 g_atomic_int_inc(&ipconfig->refcount);
957 * connman_ipconfig_unref:
958 * @ipconfig: ipconfig structure
960 * Decrease reference counter of ipconfig
962 void connman_ipconfig_unref(struct connman_ipconfig *ipconfig)
964 if (ipconfig == NULL)
967 DBG("ipconfig %p refcount %d", ipconfig,
968 g_atomic_int_get(&ipconfig->refcount) - 1);
970 if (g_atomic_int_dec_and_test(&ipconfig->refcount) == TRUE) {
971 __connman_ipconfig_disable(ipconfig);
973 connman_ipconfig_set_ops(ipconfig, NULL);
975 if (ipconfig->origin != NULL) {
976 connman_ipconfig_unref(ipconfig->origin);
977 ipconfig->origin = NULL;
980 connman_ipaddress_free(ipconfig->system);
981 connman_ipaddress_free(ipconfig->address);
987 * connman_ipconfig_get_data:
988 * @ipconfig: ipconfig structure
990 * Get private data pointer
992 void *connman_ipconfig_get_data(struct connman_ipconfig *ipconfig)
994 if (ipconfig == NULL)
997 return ipconfig->ops_data;
1001 * connman_ipconfig_set_data:
1002 * @ipconfig: ipconfig structure
1003 * @data: data pointer
1005 * Set private data pointer
1007 void connman_ipconfig_set_data(struct connman_ipconfig *ipconfig, void *data)
1009 ipconfig->ops_data = data;
1013 * connman_ipconfig_get_index:
1014 * @ipconfig: ipconfig structure
1016 * Get interface index
1018 int connman_ipconfig_get_index(struct connman_ipconfig *ipconfig)
1020 if (ipconfig == NULL)
1023 if (ipconfig->origin != NULL)
1024 return ipconfig->origin->index;
1026 return ipconfig->index;
1030 * connman_ipconfig_get_ifname:
1031 * @ipconfig: ipconfig structure
1033 * Get interface name
1035 const char *connman_ipconfig_get_ifname(struct connman_ipconfig *ipconfig)
1037 struct connman_ipdevice *ipdevice;
1039 if (ipconfig == NULL)
1042 if (ipconfig->index < 0)
1045 ipdevice = g_hash_table_lookup(ipdevice_hash,
1046 GINT_TO_POINTER(ipconfig->index));
1047 if (ipdevice == NULL)
1050 return ipdevice->ifname;
1054 * connman_ipconfig_set_ops:
1055 * @ipconfig: ipconfig structure
1056 * @ops: operation callbacks
1058 * Set the operation callbacks
1060 void connman_ipconfig_set_ops(struct connman_ipconfig *ipconfig,
1061 const struct connman_ipconfig_ops *ops)
1063 ipconfig->ops = ops;
1067 * connman_ipconfig_set_method:
1068 * @ipconfig: ipconfig structure
1069 * @method: configuration method
1071 * Set the configuration method
1073 int connman_ipconfig_set_method(struct connman_ipconfig *ipconfig,
1074 enum connman_ipconfig_method method)
1076 ipconfig->method = method;
1081 enum connman_ipconfig_method __connman_ipconfig_get_method(struct connman_ipconfig *ipconfig)
1083 if (ipconfig == NULL)
1084 return CONNMAN_IPCONFIG_METHOD_UNKNOWN;
1086 return ipconfig->method;
1090 * connman_ipconfig_bind:
1091 * @ipconfig: ipconfig structure
1092 * @ipaddress: ipaddress structure
1094 * Bind IP address details to configuration
1096 void connman_ipconfig_bind(struct connman_ipconfig *ipconfig,
1097 struct connman_ipaddress *ipaddress)
1099 struct connman_ipconfig *origin;
1101 origin = ipconfig->origin ? ipconfig->origin : ipconfig;
1103 connman_ipaddress_copy(origin->address, ipaddress);
1105 connman_inet_set_address(origin->index, origin->address);
1108 void __connman_ipconfig_set_element_ipv6_gateway(
1109 struct connman_ipconfig *ipconfig,
1110 struct connman_element *element)
1112 if (ipconfig->type == CONNMAN_IPCONFIG_TYPE_IPV6)
1113 element->ipv6.gateway = ipconfig->address->gateway;
1117 * FIXME: The element soulution should be removed in the future
1118 * Set IPv4 and IPv6 gateway
1120 int __connman_ipconfig_set_gateway(struct connman_ipconfig *ipconfig,
1121 struct connman_element *parent)
1123 struct connman_element *connection;
1125 connection = connman_element_create(NULL);
1127 DBG("ipconfig %p", ipconfig);
1129 connection->type = CONNMAN_ELEMENT_TYPE_CONNECTION;
1130 connection->index = ipconfig->index;
1132 if (ipconfig->type == CONNMAN_IPCONFIG_TYPE_IPV4)
1133 connection->ipv4.gateway = ipconfig->address->gateway;
1134 else if (ipconfig->type == CONNMAN_IPCONFIG_TYPE_IPV6)
1135 connection->ipv6.gateway = ipconfig->address->gateway;
1137 if (connman_element_register(connection, parent) < 0)
1138 connman_element_unref(connection);
1143 int __connman_ipconfig_set_address(struct connman_ipconfig *ipconfig)
1147 switch (ipconfig->method) {
1148 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
1149 case CONNMAN_IPCONFIG_METHOD_OFF:
1150 case CONNMAN_IPCONFIG_METHOD_FIXED:
1151 case CONNMAN_IPCONFIG_METHOD_DHCP:
1152 case CONNMAN_IPCONFIG_METHOD_AUTO:
1154 case CONNMAN_IPCONFIG_METHOD_MANUAL:
1155 if (ipconfig->type == CONNMAN_IPCONFIG_TYPE_IPV4)
1156 return connman_inet_set_address(ipconfig->index,
1158 else if (ipconfig->type == CONNMAN_IPCONFIG_TYPE_IPV6)
1159 return connman_inet_set_ipv6_address(
1160 ipconfig->index, ipconfig->address);
1166 int __connman_ipconfig_clear_address(struct connman_ipconfig *ipconfig)
1170 if (ipconfig == NULL)
1173 DBG("method %d", ipconfig->method);
1175 switch (ipconfig->method) {
1176 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
1177 case CONNMAN_IPCONFIG_METHOD_OFF:
1178 case CONNMAN_IPCONFIG_METHOD_FIXED:
1179 case CONNMAN_IPCONFIG_METHOD_DHCP:
1180 case CONNMAN_IPCONFIG_METHOD_AUTO:
1182 case CONNMAN_IPCONFIG_METHOD_MANUAL:
1183 if (ipconfig->type == CONNMAN_IPCONFIG_TYPE_IPV4)
1184 return connman_inet_clear_address(ipconfig->index,
1186 else if (ipconfig->type == CONNMAN_IPCONFIG_TYPE_IPV6)
1187 return connman_inet_clear_ipv6_address(
1189 ipconfig->address->local,
1190 ipconfig->address->prefixlen);
1196 int __connman_ipconfig_set_proxy_autoconfig(struct connman_ipconfig *ipconfig,
1199 struct connman_ipdevice *ipdevice;
1201 DBG("ipconfig %p", ipconfig);
1203 if (ipconfig == NULL || ipconfig->index < 0)
1206 ipdevice = g_hash_table_lookup(ipdevice_hash,
1207 GINT_TO_POINTER(ipconfig->index));
1208 if (ipdevice == NULL)
1211 g_free(ipdevice->pac);
1212 ipdevice->pac = g_strdup(url);
1217 const char *__connman_ipconfig_get_proxy_autoconfig(struct connman_ipconfig *ipconfig)
1219 struct connman_ipdevice *ipdevice;
1221 DBG("ipconfig %p", ipconfig);
1223 if (ipconfig == NULL || ipconfig->index < 0)
1226 ipdevice = g_hash_table_lookup(ipdevice_hash,
1227 GINT_TO_POINTER(ipconfig->index));
1228 if (ipdevice == NULL)
1231 return ipdevice->pac;
1234 int __connman_ipconfig_enable(struct connman_ipconfig *ipconfig)
1236 struct connman_ipdevice *ipdevice;
1237 gboolean up = FALSE, down = FALSE;
1238 gboolean lower_up = FALSE, lower_down = FALSE;
1239 enum connman_ipconfig_type type;
1241 DBG("ipconfig %p", ipconfig);
1243 if (ipconfig == NULL || ipconfig->index < 0)
1246 ipdevice = g_hash_table_lookup(ipdevice_hash,
1247 GINT_TO_POINTER(ipconfig->index));
1248 if (ipdevice == NULL)
1251 if (ipconfig->type == CONNMAN_IPCONFIG_TYPE_IPV4) {
1252 if (ipdevice->config_ipv4 == ipconfig)
1254 type = CONNMAN_IPCONFIG_TYPE_IPV4;
1255 } else if (ipconfig->type == CONNMAN_IPCONFIG_TYPE_IPV6) {
1256 if (ipdevice->config_ipv6 == ipconfig)
1258 type = CONNMAN_IPCONFIG_TYPE_IPV6;
1262 if (type == CONNMAN_IPCONFIG_TYPE_IPV4 &&
1263 ipdevice->config_ipv4 != NULL) {
1264 ipconfig_list = g_list_remove(ipconfig_list,
1265 ipdevice->config_ipv4);
1267 connman_ipaddress_clear(ipdevice->config_ipv4->system);
1269 connman_ipconfig_unref(ipdevice->config_ipv4);
1272 if (type == CONNMAN_IPCONFIG_TYPE_IPV6 &&
1273 ipdevice->config_ipv6 != NULL) {
1274 ipconfig_list = g_list_remove(ipconfig_list,
1275 ipdevice->config_ipv6);
1277 connman_ipaddress_clear(ipdevice->config_ipv6->system);
1279 connman_ipconfig_unref(ipdevice->config_ipv6);
1282 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
1283 ipdevice->config_ipv4 = connman_ipconfig_ref(ipconfig);
1284 else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
1285 ipdevice->config_ipv6 = connman_ipconfig_ref(ipconfig);
1287 ipconfig_list = g_list_append(ipconfig_list, ipconfig);
1289 if (ipdevice->flags & IFF_UP)
1294 if ((ipdevice->flags & (IFF_RUNNING | IFF_LOWER_UP)) ==
1295 (IFF_RUNNING | IFF_LOWER_UP))
1297 else if ((ipdevice->flags & (IFF_RUNNING | IFF_LOWER_UP)) == 0)
1300 if (up == TRUE && ipconfig->ops->up)
1301 ipconfig->ops->up(ipconfig);
1302 if (lower_up == TRUE && ipconfig->ops->lower_up)
1303 ipconfig->ops->lower_up(ipconfig);
1305 if (lower_down == TRUE && ipconfig->ops->lower_down)
1306 ipconfig->ops->lower_down(ipconfig);
1307 if (down == TRUE && ipconfig->ops->down)
1308 ipconfig->ops->down(ipconfig);
1313 int __connman_ipconfig_disable(struct connman_ipconfig *ipconfig)
1315 struct connman_ipdevice *ipdevice;
1317 DBG("ipconfig %p", ipconfig);
1319 if (ipconfig == NULL || ipconfig->index < 0)
1322 ipdevice = g_hash_table_lookup(ipdevice_hash,
1323 GINT_TO_POINTER(ipconfig->index));
1324 if (ipdevice == NULL)
1327 if (ipdevice->config_ipv4 == NULL && ipdevice->config_ipv6 == NULL)
1330 if (ipdevice->config_ipv4 == ipconfig) {
1331 ipconfig_list = g_list_remove(ipconfig_list, ipconfig);
1333 connman_ipaddress_clear(ipdevice->config_ipv4->system);
1334 connman_ipconfig_unref(ipdevice->config_ipv4);
1335 ipdevice->config_ipv4 = NULL;
1339 if (ipdevice->config_ipv6 == ipconfig) {
1340 ipconfig_list = g_list_remove(ipconfig_list, ipconfig);
1342 connman_ipaddress_clear(ipdevice->config_ipv6->system);
1343 connman_ipconfig_unref(ipdevice->config_ipv6);
1344 ipdevice->config_ipv6 = NULL;
1351 const char *__connman_ipconfig_method2string(enum connman_ipconfig_method method)
1354 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
1356 case CONNMAN_IPCONFIG_METHOD_OFF:
1358 case CONNMAN_IPCONFIG_METHOD_FIXED:
1360 case CONNMAN_IPCONFIG_METHOD_MANUAL:
1362 case CONNMAN_IPCONFIG_METHOD_DHCP:
1364 case CONNMAN_IPCONFIG_METHOD_AUTO:
1371 enum connman_ipconfig_method __connman_ipconfig_string2method(const char *method)
1373 if (g_strcmp0(method, "off") == 0)
1374 return CONNMAN_IPCONFIG_METHOD_OFF;
1375 else if (g_strcmp0(method, "fixed") == 0)
1376 return CONNMAN_IPCONFIG_METHOD_FIXED;
1377 else if (g_strcmp0(method, "manual") == 0)
1378 return CONNMAN_IPCONFIG_METHOD_MANUAL;
1379 else if (g_strcmp0(method, "dhcp") == 0)
1380 return CONNMAN_IPCONFIG_METHOD_DHCP;
1381 else if (g_strcmp0(method, "auto") == 0)
1382 return CONNMAN_IPCONFIG_METHOD_AUTO;
1384 return CONNMAN_IPCONFIG_METHOD_UNKNOWN;
1387 void __connman_ipconfig_append_ipv4(struct connman_ipconfig *ipconfig,
1388 DBusMessageIter *iter)
1394 if (ipconfig->type != CONNMAN_IPCONFIG_TYPE_IPV4)
1397 str = __connman_ipconfig_method2string(ipconfig->method);
1401 connman_dbus_dict_append_basic(iter, "Method", DBUS_TYPE_STRING, &str);
1403 if (ipconfig->system == NULL)
1406 if (ipconfig->system->local != NULL) {
1408 struct in_addr netmask;
1411 connman_dbus_dict_append_basic(iter, "Address",
1412 DBUS_TYPE_STRING, &ipconfig->system->local);
1414 addr = 0xffffffff << (32 - ipconfig->system->prefixlen);
1415 netmask.s_addr = htonl(addr);
1416 mask = inet_ntoa(netmask);
1417 connman_dbus_dict_append_basic(iter, "Netmask",
1418 DBUS_TYPE_STRING, &mask);
1421 if (ipconfig->system->gateway != NULL)
1422 connman_dbus_dict_append_basic(iter, "Gateway",
1423 DBUS_TYPE_STRING, &ipconfig->system->gateway);
1426 void __connman_ipconfig_append_ipv6(struct connman_ipconfig *ipconfig,
1427 DBusMessageIter *iter)
1433 if (ipconfig->type != CONNMAN_IPCONFIG_TYPE_IPV6)
1436 str = __connman_ipconfig_method2string(ipconfig->method);
1440 connman_dbus_dict_append_basic(iter, "Method", DBUS_TYPE_STRING, &str);
1442 if (ipconfig->system == NULL)
1445 if (ipconfig->system->local != NULL) {
1446 connman_dbus_dict_append_basic(iter, "Address",
1447 DBUS_TYPE_STRING, &ipconfig->system->local);
1448 connman_dbus_dict_append_basic(iter, "PrefixLength",
1450 &ipconfig->system->prefixlen);
1453 if (ipconfig->system->gateway != NULL)
1454 connman_dbus_dict_append_basic(iter, "Gateway",
1455 DBUS_TYPE_STRING, &ipconfig->system->gateway);
1458 void __connman_ipconfig_append_ipv6config(struct connman_ipconfig *ipconfig,
1459 DBusMessageIter *iter)
1465 str = __connman_ipconfig_method2string(ipconfig->method);
1469 connman_dbus_dict_append_basic(iter, "Method", DBUS_TYPE_STRING, &str);
1471 switch (ipconfig->method) {
1472 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
1473 case CONNMAN_IPCONFIG_METHOD_OFF:
1474 case CONNMAN_IPCONFIG_METHOD_DHCP:
1476 case CONNMAN_IPCONFIG_METHOD_FIXED:
1477 case CONNMAN_IPCONFIG_METHOD_MANUAL:
1478 case CONNMAN_IPCONFIG_METHOD_AUTO:
1482 if (ipconfig->address == NULL)
1485 if (ipconfig->address->local != NULL) {
1486 connman_dbus_dict_append_basic(iter, "Address",
1487 DBUS_TYPE_STRING, &ipconfig->address->local);
1488 connman_dbus_dict_append_basic(iter, "PrefixLength",
1490 &ipconfig->address->prefixlen);
1493 if (ipconfig->address->gateway != NULL)
1494 connman_dbus_dict_append_basic(iter, "Gateway",
1495 DBUS_TYPE_STRING, &ipconfig->address->gateway);
1498 void __connman_ipconfig_append_ipv4config(struct connman_ipconfig *ipconfig,
1499 DBusMessageIter *iter)
1505 str = __connman_ipconfig_method2string(ipconfig->method);
1509 connman_dbus_dict_append_basic(iter, "Method", DBUS_TYPE_STRING, &str);
1511 switch (ipconfig->method) {
1512 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
1513 case CONNMAN_IPCONFIG_METHOD_OFF:
1514 case CONNMAN_IPCONFIG_METHOD_FIXED:
1515 case CONNMAN_IPCONFIG_METHOD_DHCP:
1516 case CONNMAN_IPCONFIG_METHOD_AUTO:
1518 case CONNMAN_IPCONFIG_METHOD_MANUAL:
1522 if (ipconfig->address == NULL)
1525 if (ipconfig->address->local != NULL) {
1527 struct in_addr netmask;
1530 connman_dbus_dict_append_basic(iter, "Address",
1531 DBUS_TYPE_STRING, &ipconfig->address->local);
1533 addr = 0xffffffff << (32 - ipconfig->address->prefixlen);
1534 netmask.s_addr = htonl(addr);
1535 mask = inet_ntoa(netmask);
1536 connman_dbus_dict_append_basic(iter, "Netmask",
1537 DBUS_TYPE_STRING, &mask);
1540 if (ipconfig->address->gateway != NULL)
1541 connman_dbus_dict_append_basic(iter, "Gateway",
1542 DBUS_TYPE_STRING, &ipconfig->address->gateway);
1545 static void disable_ipv6(struct connman_ipconfig *ipconfig)
1547 struct connman_ipdevice *ipdevice;
1551 ipdevice = g_hash_table_lookup(ipdevice_hash,
1552 GINT_TO_POINTER(ipconfig->index));
1553 if (ipdevice == NULL)
1556 set_ipv6_state(ipdevice->ifname, FALSE);
1559 static void enable_ipv6(struct connman_ipconfig *ipconfig)
1561 struct connman_ipdevice *ipdevice;
1565 ipdevice = g_hash_table_lookup(ipdevice_hash,
1566 GINT_TO_POINTER(ipconfig->index));
1567 if (ipdevice == NULL)
1570 set_ipv6_state(ipdevice->ifname, TRUE);
1573 int __connman_ipconfig_set_config(struct connman_ipconfig *ipconfig,
1574 DBusMessageIter *array)
1576 enum connman_ipconfig_method method = CONNMAN_IPCONFIG_METHOD_UNKNOWN;
1577 const char *address = NULL, *netmask = NULL, *gateway = NULL,
1578 *prefix_length_string = NULL;
1579 int prefix_length = 0;
1580 DBusMessageIter dict;
1582 DBG("ipconfig %p", ipconfig);
1584 if (dbus_message_iter_get_arg_type(array) != DBUS_TYPE_ARRAY)
1587 dbus_message_iter_recurse(array, &dict);
1589 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
1590 DBusMessageIter entry;
1594 dbus_message_iter_recurse(&dict, &entry);
1596 if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING)
1599 dbus_message_iter_get_basic(&entry, &key);
1600 dbus_message_iter_next(&entry);
1602 type = dbus_message_iter_get_arg_type(&entry);
1604 if (g_str_equal(key, "Method") == TRUE) {
1607 if (type != DBUS_TYPE_STRING)
1610 dbus_message_iter_get_basic(&entry, &str);
1611 method = __connman_ipconfig_string2method(str);
1612 } else if (g_str_equal(key, "Address") == TRUE) {
1613 if (type != DBUS_TYPE_STRING)
1616 dbus_message_iter_get_basic(&entry, &address);
1617 } else if (g_str_equal(key, "PrefixLength") == TRUE) {
1618 if (type != DBUS_TYPE_STRING)
1621 dbus_message_iter_get_basic(&entry,
1622 &prefix_length_string);
1624 prefix_length = atoi(prefix_length_string);
1625 if (prefix_length < 0 || prefix_length > 128)
1628 } else if (g_str_equal(key, "Netmask") == TRUE) {
1629 if (type != DBUS_TYPE_STRING)
1632 dbus_message_iter_get_basic(&entry, &netmask);
1633 } else if (g_str_equal(key, "Gateway") == TRUE) {
1634 if (type != DBUS_TYPE_STRING)
1637 dbus_message_iter_get_basic(&entry, &gateway);
1639 dbus_message_iter_next(&dict);
1642 DBG("method %d address %s netmask %s gateway %s prefix_length %d",
1643 method, address, netmask, gateway, prefix_length);
1646 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
1647 case CONNMAN_IPCONFIG_METHOD_FIXED:
1650 case CONNMAN_IPCONFIG_METHOD_OFF:
1651 ipconfig->method = method;
1652 if (ipconfig->type == CONNMAN_IPCONFIG_TYPE_IPV6)
1653 disable_ipv6(ipconfig);
1656 case CONNMAN_IPCONFIG_METHOD_AUTO:
1657 if (ipconfig->type != CONNMAN_IPCONFIG_TYPE_IPV6)
1660 ipconfig->method = method;
1661 enable_ipv6(ipconfig);
1664 case CONNMAN_IPCONFIG_METHOD_MANUAL:
1665 if (address == NULL)
1668 ipconfig->method = method;
1670 if (ipconfig->type == CONNMAN_IPCONFIG_TYPE_IPV4)
1671 connman_ipaddress_set_ipv4(ipconfig->address,
1672 address, netmask, gateway);
1674 return connman_ipaddress_set_ipv6(
1675 ipconfig->address, address,
1676 gateway, prefix_length);
1679 case CONNMAN_IPCONFIG_METHOD_DHCP:
1680 if (ipconfig->type == CONNMAN_IPCONFIG_TYPE_IPV6)
1683 ipconfig->method = method;
1690 void __connman_ipconfig_append_ethernet(struct connman_ipconfig *ipconfig,
1691 DBusMessageIter *iter)
1693 struct connman_ipdevice *ipdevice;
1694 const char *method = "auto";
1696 connman_dbus_dict_append_basic(iter, "Method",
1697 DBUS_TYPE_STRING, &method);
1699 ipdevice = g_hash_table_lookup(ipdevice_hash,
1700 GINT_TO_POINTER(ipconfig->index));
1701 if (ipdevice == NULL)
1704 if (ipdevice->ifname != NULL)
1705 connman_dbus_dict_append_basic(iter, "Interface",
1706 DBUS_TYPE_STRING, &ipdevice->ifname);
1708 if (ipdevice->address != NULL)
1709 connman_dbus_dict_append_basic(iter, "Address",
1710 DBUS_TYPE_STRING, &ipdevice->address);
1712 if (ipdevice->mtu > 0)
1713 connman_dbus_dict_append_basic(iter, "MTU",
1714 DBUS_TYPE_UINT16, &ipdevice->mtu);
1717 int __connman_ipconfig_load(struct connman_ipconfig *ipconfig,
1718 GKeyFile *keyfile, const char *identifier, const char *prefix)
1723 DBG("ipconfig %p identifier %s", ipconfig, identifier);
1725 key = g_strdup_printf("%smethod", prefix);
1726 method = g_key_file_get_string(keyfile, identifier, key, NULL);
1727 if (method == NULL) {
1728 if (ipconfig->type == CONNMAN_IPCONFIG_TYPE_IPV4)
1729 ipconfig->method = CONNMAN_IPCONFIG_METHOD_DHCP;
1731 ipconfig->method = CONNMAN_IPCONFIG_METHOD_OFF;
1733 ipconfig->method = __connman_ipconfig_string2method(method);
1735 if (ipconfig->method == CONNMAN_IPCONFIG_METHOD_UNKNOWN)
1736 ipconfig->method = CONNMAN_IPCONFIG_METHOD_OFF;
1741 key = g_strdup_printf("%snetmask_prefixlen", prefix);
1742 ipconfig->address->prefixlen = g_key_file_get_integer(
1743 keyfile, identifier, key, NULL);
1746 key = g_strdup_printf("%slocal_address", prefix);
1747 ipconfig->address->local = g_key_file_get_string(
1748 keyfile, identifier, key, NULL);
1751 key = g_strdup_printf("%speer_address", prefix);
1752 ipconfig->address->peer = g_key_file_get_string(
1753 keyfile, identifier, key, NULL);
1756 key = g_strdup_printf("%sbroadcast_address", prefix);
1757 ipconfig->address->broadcast = g_key_file_get_string(
1758 keyfile, identifier, key, NULL);
1761 key = g_strdup_printf("%sgateway", prefix);
1762 ipconfig->address->gateway = g_key_file_get_string(
1763 keyfile, identifier, key, NULL);
1769 int __connman_ipconfig_save(struct connman_ipconfig *ipconfig,
1770 GKeyFile *keyfile, const char *identifier, const char *prefix)
1775 DBG("ipconfig %p identifier %s", ipconfig, identifier);
1777 method = __connman_ipconfig_method2string(ipconfig->method);
1779 key = g_strdup_printf("%smethod", prefix);
1780 g_key_file_set_string(keyfile, identifier, key, method);
1783 key = g_strdup_printf("%snetmask_prefixlen", prefix);
1784 g_key_file_set_integer(keyfile, identifier,
1785 key, ipconfig->address->prefixlen);
1788 key = g_strdup_printf("%slocal_address", prefix);
1789 if (ipconfig->address->local != NULL)
1790 g_key_file_set_string(keyfile, identifier,
1791 key, ipconfig->address->local);
1794 key = g_strdup_printf("%speer_address", prefix);
1795 if (ipconfig->address->peer != NULL)
1796 g_key_file_set_string(keyfile, identifier,
1797 key, ipconfig->address->peer);
1800 key = g_strdup_printf("%sbroadcast_address", prefix);
1801 if (ipconfig->address->broadcast != NULL)
1802 g_key_file_set_string(keyfile, identifier,
1803 key, ipconfig->address->broadcast);
1806 key = g_strdup_printf("%sgateway", prefix);
1807 if (ipconfig->address->gateway != NULL)
1808 g_key_file_set_string(keyfile, identifier,
1809 key, ipconfig->address->gateway);
1815 int __connman_ipconfig_init(void)
1819 ipdevice_hash = g_hash_table_new_full(g_direct_hash, g_direct_equal,
1820 NULL, free_ipdevice);
1825 void __connman_ipconfig_cleanup(void)
1829 g_hash_table_destroy(ipdevice_hash);
1830 ipdevice_hash = NULL;