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
27 #include <net/if_arp.h>
28 #include <linux/if_link.h>
33 #define IFF_LOWER_UP 0x10000
40 struct connman_ipconfig {
43 enum connman_ipconfig_type type;
45 struct connman_ipconfig *origin;
47 const struct connman_ipconfig_ops *ops;
50 enum connman_ipconfig_method method;
51 struct connman_ipaddress *address;
52 struct connman_ipaddress *system;
54 struct connman_ipconfig *ipv6;
57 struct connman_ipdevice {
80 struct connman_ipconfig *config;
82 struct connman_ipconfig_driver *driver;
83 struct connman_ipconfig *driver_config;
86 static GHashTable *ipdevice_hash = NULL;
87 static GList *ipconfig_list = NULL;
89 struct connman_ipaddress *connman_ipaddress_alloc(int family)
91 struct connman_ipaddress *ipaddress;
93 ipaddress = g_try_new0(struct connman_ipaddress, 1);
94 if (ipaddress == NULL)
97 ipaddress->family = family;
98 ipaddress->prefixlen = 0;
99 ipaddress->local = NULL;
100 ipaddress->peer = NULL;
101 ipaddress->broadcast = NULL;
102 ipaddress->gateway = NULL;
107 void connman_ipaddress_free(struct connman_ipaddress *ipaddress)
109 if (ipaddress == NULL)
112 g_free(ipaddress->broadcast);
113 g_free(ipaddress->peer);
114 g_free(ipaddress->local);
115 g_free(ipaddress->gateway);
119 static unsigned char netmask2prefixlen(const char *netmask)
121 unsigned char bits = 0;
122 in_addr_t mask = inet_network(netmask);
123 in_addr_t host = ~mask;
125 /* a valid netmask must be 2^n - 1 */
126 if ((host & (host + 1)) != 0)
129 for (; mask; mask <<= 1)
135 static gboolean check_ipv6_address(const char *address)
137 unsigned char buf[sizeof(struct in6_addr)];
140 err = inet_pton(AF_INET6, address, buf);
147 int connman_ipaddress_set_ipv6(struct connman_ipaddress *ipaddress,
148 const char *address, const char *gateway,
149 unsigned char prefix_length)
151 if (ipaddress == NULL)
154 if (check_ipv6_address(address) == FALSE)
157 if (check_ipv6_address(gateway) == FALSE)
160 DBG("prefix_len %d address %s gateway %s",
161 prefix_length, address, gateway);
163 ipaddress->prefixlen = prefix_length;
165 g_free(ipaddress->local);
166 ipaddress->local = g_strdup(address);
168 g_free(ipaddress->gateway);
169 ipaddress->gateway = g_strdup(gateway);
174 void connman_ipaddress_set_ipv4(struct connman_ipaddress *ipaddress,
175 const char *address, const char *netmask, const char *gateway)
177 if (ipaddress == NULL)
181 ipaddress->prefixlen = netmask2prefixlen(netmask);
183 ipaddress->prefixlen = 32;
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 free_ipdevice(gpointer data)
297 struct connman_ipdevice *ipdevice = data;
299 connman_info("%s {remove} index %d", ipdevice->ifname,
302 if (ipdevice->config != NULL)
303 connman_ipconfig_unref(ipdevice->config);
305 free_address_list(ipdevice);
306 g_free(ipdevice->ipv4_gateway);
307 g_free(ipdevice->ipv6_gateway);
308 g_free(ipdevice->proxy);
309 g_free(ipdevice->pac);
311 g_free(ipdevice->address);
312 g_free(ipdevice->ifname);
316 static GSList *driver_list = NULL;
318 static gint compare_priority(gconstpointer a, gconstpointer b)
320 const struct connman_ipconfig_driver *driver1 = a;
321 const struct connman_ipconfig_driver *driver2 = b;
323 return driver2->priority - driver1->priority;
327 * connman_ipconfig_driver_register:
328 * @driver: IP configuration driver
330 * Register a new IP configuration driver
332 * Returns: %0 on success
334 int connman_ipconfig_driver_register(struct connman_ipconfig_driver *driver)
336 DBG("driver %p name %s", driver, driver->name);
338 driver_list = g_slist_insert_sorted(driver_list, driver,
345 * connman_ipconfig_driver_unregister:
346 * @driver: IP configuration driver
348 * Remove a previously registered IP configuration driver.
350 void connman_ipconfig_driver_unregister(struct connman_ipconfig_driver *driver)
352 DBG("driver %p name %s", driver, driver->name);
354 driver_list = g_slist_remove(driver_list, driver);
357 static void __connman_ipconfig_lower_up(struct connman_ipdevice *ipdevice)
361 DBG("ipconfig %p", ipdevice->config);
363 if (ipdevice->config == NULL)
366 switch (ipdevice->config->method) {
367 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
368 case CONNMAN_IPCONFIG_METHOD_OFF:
369 case CONNMAN_IPCONFIG_METHOD_FIXED:
370 case CONNMAN_IPCONFIG_METHOD_MANUAL:
372 case CONNMAN_IPCONFIG_METHOD_DHCP:
376 if (ipdevice->driver != NULL)
379 ipdevice->driver_config = connman_ipconfig_clone(ipdevice->config);
380 if (ipdevice->driver_config == NULL)
383 for (list = driver_list; list; list = list->next) {
384 struct connman_ipconfig_driver *driver = list->data;
386 if (driver->request(ipdevice->driver_config) == 0) {
387 ipdevice->driver = driver;
392 if (ipdevice->driver == NULL) {
393 connman_ipconfig_unref(ipdevice->driver_config);
394 ipdevice->driver_config = NULL;
398 static void __connman_ipconfig_lower_down(struct connman_ipdevice *ipdevice)
400 DBG("ipconfig %p", ipdevice->config);
402 if (ipdevice->config == NULL)
405 if (ipdevice->driver == NULL)
408 ipdevice->driver->release(ipdevice->driver_config);
410 ipdevice->driver = NULL;
412 connman_ipconfig_unref(ipdevice->driver_config);
413 ipdevice->driver_config = NULL;
415 connman_inet_clear_address(ipdevice->index);
416 connman_inet_clear_ipv6_address(ipdevice->index,
417 ipdevice->driver_config->address->local,
418 ipdevice->driver_config->address->prefixlen);
421 static void update_stats(struct connman_ipdevice *ipdevice,
422 struct rtnl_link_stats *stats)
424 if (stats->rx_packets == 0 && stats->tx_packets == 0)
427 connman_info("%s {RX} %u packets %u bytes", ipdevice->ifname,
428 stats->rx_packets, stats->rx_bytes);
429 connman_info("%s {TX} %u packets %u bytes", ipdevice->ifname,
430 stats->tx_packets, stats->tx_bytes);
432 if (ipdevice->config == NULL)
435 ipdevice->rx_packets = stats->rx_packets;
436 ipdevice->tx_packets = stats->tx_packets;
437 ipdevice->rx_bytes = stats->rx_bytes;
438 ipdevice->tx_bytes = stats->tx_bytes;
439 ipdevice->rx_errors = stats->rx_errors;
440 ipdevice->tx_errors = stats->tx_errors;
441 ipdevice->rx_dropped = stats->rx_dropped;
442 ipdevice->tx_dropped = stats->tx_dropped;
444 __connman_service_notify(ipdevice->config,
445 ipdevice->rx_packets, ipdevice->tx_packets,
446 ipdevice->rx_bytes, ipdevice->tx_bytes,
447 ipdevice->rx_errors, ipdevice->tx_errors,
448 ipdevice->rx_dropped, ipdevice->tx_dropped);
451 void __connman_ipconfig_newlink(int index, unsigned short type,
452 unsigned int flags, const char *address,
454 struct rtnl_link_stats *stats)
456 struct connman_ipdevice *ipdevice;
459 gboolean up = FALSE, down = FALSE;
460 gboolean lower_up = FALSE, lower_down = FALSE;
462 DBG("index %d", index);
464 if (type == ARPHRD_LOOPBACK)
467 ipdevice = g_hash_table_lookup(ipdevice_hash, GINT_TO_POINTER(index));
468 if (ipdevice != NULL)
471 ipdevice = g_try_new0(struct connman_ipdevice, 1);
472 if (ipdevice == NULL)
475 ipdevice->index = index;
476 ipdevice->ifname = connman_inet_ifname(index);
477 ipdevice->type = type;
479 ipdevice->address = g_strdup(address);
481 g_hash_table_insert(ipdevice_hash, GINT_TO_POINTER(index), ipdevice);
483 connman_info("%s {create} index %d type %d <%s>", ipdevice->ifname,
484 index, type, type2str(type));
489 update_stats(ipdevice, stats);
491 if (flags == ipdevice->flags)
494 if ((ipdevice->flags & IFF_UP) != (flags & IFF_UP)) {
501 if ((ipdevice->flags & (IFF_RUNNING | IFF_LOWER_UP)) !=
502 (flags & (IFF_RUNNING | IFF_LOWER_UP))) {
503 if ((flags & (IFF_RUNNING | IFF_LOWER_UP)) ==
504 (IFF_RUNNING | IFF_LOWER_UP))
506 else if ((flags & (IFF_RUNNING | IFF_LOWER_UP)) == 0)
510 ipdevice->flags = flags;
512 str = g_string_new(NULL);
517 g_string_append(str, "UP");
519 g_string_append(str, "DOWN");
521 if (flags & IFF_RUNNING)
522 g_string_append(str, ",RUNNING");
524 if (flags & IFF_LOWER_UP)
525 g_string_append(str, ",LOWER_UP");
527 connman_info("%s {update} flags %u <%s>", ipdevice->ifname,
530 g_string_free(str, TRUE);
532 for (list = g_list_first(ipconfig_list); list;
533 list = g_list_next(list)) {
534 struct connman_ipconfig *ipconfig = list->data;
536 if (index != ipconfig->index)
539 if (ipconfig->ops == NULL)
542 if (up == TRUE && ipconfig->ops->up)
543 ipconfig->ops->up(ipconfig);
544 if (lower_up == TRUE && ipconfig->ops->lower_up)
545 ipconfig->ops->lower_up(ipconfig);
547 if (lower_down == TRUE && ipconfig->ops->lower_down)
548 ipconfig->ops->lower_down(ipconfig);
549 if (down == TRUE && ipconfig->ops->down)
550 ipconfig->ops->down(ipconfig);
554 __connman_ipconfig_lower_up(ipdevice);
556 __connman_ipconfig_lower_down(ipdevice);
559 void __connman_ipconfig_dellink(int index, struct rtnl_link_stats *stats)
561 struct connman_ipdevice *ipdevice;
564 DBG("index %d", index);
566 ipdevice = g_hash_table_lookup(ipdevice_hash, GINT_TO_POINTER(index));
567 if (ipdevice == NULL)
570 update_stats(ipdevice, stats);
572 for (list = g_list_first(ipconfig_list); list;
573 list = g_list_next(list)) {
574 struct connman_ipconfig *ipconfig = list->data;
576 if (index != ipconfig->index)
579 ipconfig->index = -1;
581 if (ipconfig->ops == NULL)
584 if (ipconfig->ops->lower_down)
585 ipconfig->ops->lower_down(ipconfig);
586 if (ipconfig->ops->down)
587 ipconfig->ops->down(ipconfig);
590 __connman_ipconfig_lower_down(ipdevice);
592 g_hash_table_remove(ipdevice_hash, GINT_TO_POINTER(index));
595 void __connman_ipconfig_newaddr(int index, int family, const char *label,
596 unsigned char prefixlen, const char *address)
598 struct connman_ipdevice *ipdevice;
599 struct connman_ipaddress *ipaddress;
602 DBG("index %d", index);
604 ipdevice = g_hash_table_lookup(ipdevice_hash, GINT_TO_POINTER(index));
605 if (ipdevice == NULL)
608 ipaddress = connman_ipaddress_alloc(family);
609 if (ipaddress == NULL)
612 ipaddress->prefixlen = prefixlen;
613 ipaddress->local = g_strdup(address);
615 ipdevice->address_list = g_slist_append(ipdevice->address_list,
618 connman_info("%s {add} address %s/%u label %s", ipdevice->ifname,
619 address, prefixlen, label);
621 if (ipdevice->config != NULL) {
622 if (family == AF_INET6 && ipdevice->config->ipv6 != NULL)
623 connman_ipaddress_copy(ipdevice->config->ipv6->system,
626 connman_ipaddress_copy(ipdevice->config->system,
630 if ((ipdevice->flags & (IFF_RUNNING | IFF_LOWER_UP)) != (IFF_RUNNING | IFF_LOWER_UP))
633 if (g_slist_length(ipdevice->address_list) > 1)
636 for (list = g_list_first(ipconfig_list); list;
637 list = g_list_next(list)) {
638 struct connman_ipconfig *ipconfig = list->data;
640 if (index != ipconfig->index)
643 if (ipconfig->ops == NULL)
646 if (ipconfig->ops->ip_bound)
647 ipconfig->ops->ip_bound(ipconfig);
651 void __connman_ipconfig_deladdr(int index, int family, const char *label,
652 unsigned char prefixlen, const char *address)
654 struct connman_ipdevice *ipdevice;
655 struct connman_ipaddress *ipaddress;
658 DBG("index %d", index);
660 ipdevice = g_hash_table_lookup(ipdevice_hash, GINT_TO_POINTER(index));
661 if (ipdevice == NULL)
664 ipaddress = find_ipaddress(ipdevice, prefixlen, address);
665 if (ipaddress == NULL)
668 ipdevice->address_list = g_slist_remove(ipdevice->address_list,
671 connman_ipaddress_free(ipaddress);
673 connman_info("%s {del} address %s/%u label %s", ipdevice->ifname,
674 address, prefixlen, label);
676 if ((ipdevice->flags & (IFF_RUNNING | IFF_LOWER_UP)) != (IFF_RUNNING | IFF_LOWER_UP))
679 if (g_slist_length(ipdevice->address_list) > 0)
682 for (list = g_list_first(ipconfig_list); list;
683 list = g_list_next(list)) {
684 struct connman_ipconfig *ipconfig = list->data;
686 if (index != ipconfig->index)
689 if (ipconfig->ops == NULL)
692 if (ipconfig->ops->ip_release)
693 ipconfig->ops->ip_release(ipconfig);
697 void __connman_ipconfig_newroute(int index, int family, unsigned char scope,
698 const char *dst, const char *gateway)
700 struct connman_ipdevice *ipdevice;
702 DBG("index %d", index);
704 ipdevice = g_hash_table_lookup(ipdevice_hash, GINT_TO_POINTER(index));
705 if (ipdevice == NULL)
708 if (scope == 0 && g_strcmp0(dst, "0.0.0.0") == 0) {
712 if (family == AF_INET6) {
713 g_free(ipdevice->ipv6_gateway);
714 ipdevice->ipv6_gateway = g_strdup(gateway);
716 g_free(ipdevice->ipv4_gateway);
717 ipdevice->ipv4_gateway = g_strdup(gateway);
720 if (ipdevice->config != NULL &&
721 ipdevice->config->system != NULL) {
722 g_free(ipdevice->config->system->gateway);
723 ipdevice->config->system->gateway = g_strdup(gateway);
726 for (list = ipdevice->address_list; list; list = list->next) {
727 struct connman_ipaddress *ipaddress = list->data;
729 g_free(ipaddress->gateway);
730 ipaddress->gateway = g_strdup(gateway);
733 for (config_list = g_list_first(ipconfig_list); config_list;
734 config_list = g_list_next(config_list)) {
735 struct connman_ipconfig *ipconfig = config_list->data;
737 if (index != ipconfig->index)
740 if (ipconfig->ops == NULL)
743 if (ipconfig->ops->ip_bound)
744 ipconfig->ops->ip_bound(ipconfig);
748 connman_info("%s {add} route %s gw %s scope %u <%s>",
749 ipdevice->ifname, dst, gateway,
750 scope, scope2str(scope));
753 void __connman_ipconfig_delroute(int index, int family, unsigned char scope,
754 const char *dst, const char *gateway)
756 struct connman_ipdevice *ipdevice;
758 DBG("index %d", index);
760 ipdevice = g_hash_table_lookup(ipdevice_hash, GINT_TO_POINTER(index));
761 if (ipdevice == NULL)
764 if (scope == 0 && g_strcmp0(dst, "0.0.0.0") == 0) {
768 if (family == AF_INET6) {
769 g_free(ipdevice->ipv6_gateway);
770 ipdevice->ipv6_gateway = NULL;
772 g_free(ipdevice->ipv4_gateway);
773 ipdevice->ipv4_gateway = NULL;
776 if (ipdevice->config != NULL &&
777 ipdevice->config->system != NULL) {
778 g_free(ipdevice->config->system->gateway);
779 ipdevice->config->system->gateway = NULL;
782 for (list = ipdevice->address_list; list; list = list->next) {
783 struct connman_ipaddress *ipaddress = list->data;
785 g_free(ipaddress->gateway);
786 ipaddress->gateway = NULL;
789 for (config_list = g_list_first(ipconfig_list); config_list;
790 config_list = g_list_next(config_list)) {
791 struct connman_ipconfig *ipconfig = config_list->data;
793 if (index != ipconfig->index)
796 if (ipconfig->ops == NULL)
799 if (ipconfig->ops->ip_release)
800 ipconfig->ops->ip_release(ipconfig);
804 connman_info("%s {del} route %s gw %s scope %u <%s>",
805 ipdevice->ifname, dst, gateway,
806 scope, scope2str(scope));
809 void __connman_ipconfig_foreach(void (*function) (int index, void *user_data),
814 keys = g_hash_table_get_keys(ipdevice_hash);
818 for (list = g_list_first(keys); list; list = g_list_next(list)) {
819 int index = GPOINTER_TO_INT(list->data);
821 function(index, user_data);
827 unsigned short __connman_ipconfig_get_type(int index)
829 struct connman_ipdevice *ipdevice;
831 ipdevice = g_hash_table_lookup(ipdevice_hash, GINT_TO_POINTER(index));
832 if (ipdevice == NULL)
835 return ipdevice->type;
838 unsigned int __connman_ipconfig_get_flags(int index)
840 struct connman_ipdevice *ipdevice;
842 ipdevice = g_hash_table_lookup(ipdevice_hash, GINT_TO_POINTER(index));
843 if (ipdevice == NULL)
846 return ipdevice->flags;
849 const char *__connman_ipconfig_get_gateway(int index)
851 struct connman_ipdevice *ipdevice;
853 ipdevice = g_hash_table_lookup(ipdevice_hash, GINT_TO_POINTER(index));
854 if (ipdevice == NULL)
857 if (ipdevice->ipv4_gateway != NULL)
858 return ipdevice->ipv4_gateway;
860 if (ipdevice->config != NULL &&
861 ipdevice->config->address != NULL)
862 return ipdevice->config->address->gateway;
867 void __connman_ipconfig_set_index(struct connman_ipconfig *ipconfig, int index)
869 ipconfig->index = index;
871 if (ipconfig->ipv6 != NULL)
872 ipconfig->ipv6->index = index;
875 static struct connman_ipconfig *create_ipv6config(int index)
877 struct connman_ipconfig *ipv6config;
879 DBG("index %d", index);
881 ipv6config = g_try_new0(struct connman_ipconfig, 1);
882 if (ipv6config == NULL)
885 ipv6config->index = index;
886 ipv6config->type = CONNMAN_IPCONFIG_TYPE_IPV6;
887 ipv6config->method = CONNMAN_IPCONFIG_METHOD_OFF;
889 ipv6config->address = connman_ipaddress_alloc(AF_INET6);
890 if (ipv6config->address == NULL) {
895 ipv6config->system = connman_ipaddress_alloc(AF_INET6);
897 ipv6config->ipv6 = NULL;
899 DBG("ipconfig %p", ipv6config);
905 * connman_ipconfig_create:
907 * Allocate a new ipconfig structure.
909 * Returns: a newly-allocated #connman_ipconfig structure
911 struct connman_ipconfig *connman_ipconfig_create(int index)
913 struct connman_ipconfig *ipconfig;
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 ipconfig->ipv6 = create_ipv6config(index);
936 DBG("ipconfig %p", ipconfig);
942 * connman_ipconfig_clone:
944 * Clone an ipconfig structure and create new reference.
946 * Returns: a newly-allocated #connman_ipconfig structure
948 struct connman_ipconfig *connman_ipconfig_clone(struct connman_ipconfig *ipconfig)
950 struct connman_ipconfig *ipconfig_clone;
952 DBG("ipconfig %p", ipconfig);
954 ipconfig_clone = g_try_new0(struct connman_ipconfig, 1);
955 if (ipconfig_clone == NULL)
958 ipconfig_clone->refcount = 1;
960 ipconfig_clone->origin = connman_ipconfig_ref(ipconfig);
962 ipconfig_clone->index = -1;
964 return ipconfig_clone;
968 * connman_ipconfig_ref:
969 * @ipconfig: ipconfig structure
971 * Increase reference counter of ipconfig
973 struct connman_ipconfig *connman_ipconfig_ref(struct connman_ipconfig *ipconfig)
975 g_atomic_int_inc(&ipconfig->refcount);
980 static void free_ipv6config(struct connman_ipconfig *ipconfig)
982 if (ipconfig == NULL)
985 connman_ipconfig_set_ops(ipconfig, NULL);
986 connman_ipaddress_free(ipconfig->system);
987 connman_ipaddress_free(ipconfig->address);
988 g_free(ipconfig->ipv6);
992 * connman_ipconfig_unref:
993 * @ipconfig: ipconfig structure
995 * Decrease reference counter of ipconfig
997 void connman_ipconfig_unref(struct connman_ipconfig *ipconfig)
999 if (g_atomic_int_dec_and_test(&ipconfig->refcount) == TRUE) {
1000 __connman_ipconfig_disable(ipconfig);
1002 connman_ipconfig_set_ops(ipconfig, NULL);
1004 if (ipconfig->origin != NULL) {
1005 connman_ipconfig_unref(ipconfig->origin);
1006 ipconfig->origin = NULL;
1009 connman_ipaddress_free(ipconfig->system);
1010 connman_ipaddress_free(ipconfig->address);
1011 free_ipv6config(ipconfig->ipv6);
1017 * connman_ipconfig_get_data:
1018 * @ipconfig: ipconfig structure
1020 * Get private data pointer
1022 void *connman_ipconfig_get_data(struct connman_ipconfig *ipconfig)
1024 return ipconfig->ops_data;
1028 * connman_ipconfig_set_data:
1029 * @ipconfig: ipconfig structure
1030 * @data: data pointer
1032 * Set private data pointer
1034 void connman_ipconfig_set_data(struct connman_ipconfig *ipconfig, void *data)
1036 ipconfig->ops_data = data;
1040 * connman_ipconfig_get_index:
1041 * @ipconfig: ipconfig structure
1043 * Get interface index
1045 int connman_ipconfig_get_index(struct connman_ipconfig *ipconfig)
1047 if (ipconfig == NULL)
1050 if (ipconfig->origin != NULL)
1051 return ipconfig->origin->index;
1053 return ipconfig->index;
1057 * connman_ipconfig_get_ifname:
1058 * @ipconfig: ipconfig structure
1060 * Get interface name
1062 const char *connman_ipconfig_get_ifname(struct connman_ipconfig *ipconfig)
1064 struct connman_ipdevice *ipdevice;
1066 if (ipconfig == NULL)
1069 if (ipconfig->index < 0)
1072 ipdevice = g_hash_table_lookup(ipdevice_hash,
1073 GINT_TO_POINTER(ipconfig->index));
1074 if (ipdevice == NULL)
1077 return ipdevice->ifname;
1081 * connman_ipconfig_set_ops:
1082 * @ipconfig: ipconfig structure
1083 * @ops: operation callbacks
1085 * Set the operation callbacks
1087 void connman_ipconfig_set_ops(struct connman_ipconfig *ipconfig,
1088 const struct connman_ipconfig_ops *ops)
1090 ipconfig->ops = ops;
1093 struct connman_ipconfig *connman_ipconfig_get_ipv6config(
1094 struct connman_ipconfig *ipconfig)
1096 if (ipconfig == NULL)
1099 return ipconfig->ipv6;
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 element->ipv6.gateway = ipconfig->ipv6->address->gateway;
1152 * FIXME: The element soulution should be removed in the future
1153 * Set IPv4 and IPv6 gateway
1155 int __connman_ipconfig_set_gateway(struct connman_ipconfig *ipconfig,
1156 struct connman_element *parent)
1158 struct connman_element *connection;
1160 connection = connman_element_create(NULL);
1162 DBG("ipconfig %p", ipconfig);
1164 connection->type = CONNMAN_ELEMENT_TYPE_CONNECTION;
1165 connection->index = ipconfig->index;
1166 connection->ipv4.gateway = ipconfig->address->gateway;
1167 connection->ipv6.gateway = ipconfig->ipv6->address->gateway;
1169 if (connman_element_register(connection, parent) < 0)
1170 connman_element_unref(connection);
1175 int __connman_ipconfig_set_address(struct connman_ipconfig *ipconfig)
1179 switch (ipconfig->method) {
1180 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
1181 case CONNMAN_IPCONFIG_METHOD_OFF:
1182 case CONNMAN_IPCONFIG_METHOD_FIXED:
1183 case CONNMAN_IPCONFIG_METHOD_DHCP:
1185 case CONNMAN_IPCONFIG_METHOD_MANUAL:
1186 if (ipconfig->type == CONNMAN_IPCONFIG_TYPE_IPV4)
1187 return connman_inet_set_address(ipconfig->index,
1189 else if (ipconfig->type == CONNMAN_IPCONFIG_TYPE_IPV6)
1190 return connman_inet_set_ipv6_address(
1191 ipconfig->index, ipconfig->address);
1197 int __connman_ipconfig_clear_address(struct connman_ipconfig *ipconfig)
1201 if (ipconfig == NULL)
1204 DBG("method %d", ipconfig->method);
1206 switch (ipconfig->method) {
1207 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
1208 case CONNMAN_IPCONFIG_METHOD_OFF:
1209 case CONNMAN_IPCONFIG_METHOD_FIXED:
1210 case CONNMAN_IPCONFIG_METHOD_DHCP:
1212 case CONNMAN_IPCONFIG_METHOD_MANUAL:
1213 if (ipconfig->type == CONNMAN_IPCONFIG_TYPE_IPV4)
1214 return connman_inet_clear_address(ipconfig->index);
1215 else if (ipconfig->type == CONNMAN_IPCONFIG_TYPE_IPV6)
1216 return connman_inet_clear_ipv6_address(
1218 ipconfig->address->local,
1219 ipconfig->address->prefixlen);
1225 int __connman_ipconfig_set_proxy_autoconfig(struct connman_ipconfig *ipconfig,
1228 struct connman_ipdevice *ipdevice;
1230 DBG("ipconfig %p", ipconfig);
1232 if (ipconfig == NULL || ipconfig->index < 0)
1235 ipdevice = g_hash_table_lookup(ipdevice_hash,
1236 GINT_TO_POINTER(ipconfig->index));
1237 if (ipdevice == NULL)
1240 g_free(ipdevice->pac);
1241 ipdevice->pac = g_strdup(url);
1246 const char *__connman_ipconfig_get_proxy_autoconfig(struct connman_ipconfig *ipconfig)
1248 struct connman_ipdevice *ipdevice;
1250 DBG("ipconfig %p", ipconfig);
1252 if (ipconfig == NULL || ipconfig->index < 0)
1255 ipdevice = g_hash_table_lookup(ipdevice_hash,
1256 GINT_TO_POINTER(ipconfig->index));
1257 if (ipdevice == NULL)
1260 return ipdevice->pac;
1263 int __connman_ipconfig_enable(struct connman_ipconfig *ipconfig)
1265 struct connman_ipdevice *ipdevice;
1266 gboolean up = FALSE, down = FALSE;
1267 gboolean lower_up = FALSE, lower_down = FALSE;
1269 DBG("ipconfig %p", ipconfig);
1271 if (ipconfig == NULL || ipconfig->index < 0)
1274 ipdevice = g_hash_table_lookup(ipdevice_hash,
1275 GINT_TO_POINTER(ipconfig->index));
1276 if (ipdevice == NULL)
1279 if (ipdevice->config == ipconfig)
1282 if (ipdevice->config != NULL) {
1283 ipconfig_list = g_list_remove(ipconfig_list, ipconfig);
1285 connman_ipaddress_clear(ipdevice->config->system);
1287 connman_ipconfig_unref(ipdevice->config);
1290 ipdevice->config = connman_ipconfig_ref(ipconfig);
1292 ipconfig_list = g_list_append(ipconfig_list, ipconfig);
1294 if (ipdevice->flags & IFF_UP)
1299 if ((ipdevice->flags & (IFF_RUNNING | IFF_LOWER_UP)) ==
1300 (IFF_RUNNING | IFF_LOWER_UP))
1302 else if ((ipdevice->flags & (IFF_RUNNING | IFF_LOWER_UP)) == 0)
1305 if (up == TRUE && ipconfig->ops->up)
1306 ipconfig->ops->up(ipconfig);
1307 if (lower_up == TRUE && ipconfig->ops->lower_up)
1308 ipconfig->ops->lower_up(ipconfig);
1310 if (lower_down == TRUE && ipconfig->ops->lower_down)
1311 ipconfig->ops->lower_down(ipconfig);
1312 if (down == TRUE && ipconfig->ops->down)
1313 ipconfig->ops->down(ipconfig);
1318 int __connman_ipconfig_disable(struct connman_ipconfig *ipconfig)
1320 struct connman_ipdevice *ipdevice;
1322 DBG("ipconfig %p", ipconfig);
1324 if (ipconfig == NULL || ipconfig->index < 0)
1327 ipdevice = g_hash_table_lookup(ipdevice_hash,
1328 GINT_TO_POINTER(ipconfig->index));
1329 if (ipdevice == NULL)
1332 if (ipdevice->config == NULL || ipdevice->config != ipconfig)
1335 ipconfig_list = g_list_remove(ipconfig_list, ipconfig);
1337 connman_ipaddress_clear(ipdevice->config->system);
1338 connman_ipaddress_clear(ipdevice->config->ipv6->system);
1340 connman_ipconfig_unref(ipdevice->config);
1341 ipdevice->config = NULL;
1346 const char *__connman_ipconfig_method2string(enum connman_ipconfig_method method)
1349 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
1351 case CONNMAN_IPCONFIG_METHOD_OFF:
1353 case CONNMAN_IPCONFIG_METHOD_FIXED:
1355 case CONNMAN_IPCONFIG_METHOD_MANUAL:
1357 case CONNMAN_IPCONFIG_METHOD_DHCP:
1364 enum connman_ipconfig_method __connman_ipconfig_string2method(const char *method)
1366 if (g_strcmp0(method, "off") == 0)
1367 return CONNMAN_IPCONFIG_METHOD_OFF;
1368 else if (g_strcmp0(method, "fixed") == 0)
1369 return CONNMAN_IPCONFIG_METHOD_FIXED;
1370 else if (g_strcmp0(method, "manual") == 0)
1371 return CONNMAN_IPCONFIG_METHOD_MANUAL;
1372 else if (g_strcmp0(method, "dhcp") == 0)
1373 return CONNMAN_IPCONFIG_METHOD_DHCP;
1375 return CONNMAN_IPCONFIG_METHOD_UNKNOWN;
1378 void __connman_ipconfig_append_ipv4(struct connman_ipconfig *ipconfig,
1379 DBusMessageIter *iter)
1385 str = __connman_ipconfig_method2string(ipconfig->method);
1389 connman_dbus_dict_append_basic(iter, "Method", DBUS_TYPE_STRING, &str);
1391 if (ipconfig->system == NULL)
1394 if (ipconfig->system->local != NULL) {
1396 struct in_addr netmask;
1399 connman_dbus_dict_append_basic(iter, "Address",
1400 DBUS_TYPE_STRING, &ipconfig->system->local);
1402 addr = 0xffffffff << (32 - ipconfig->system->prefixlen);
1403 netmask.s_addr = htonl(addr);
1404 mask = inet_ntoa(netmask);
1405 connman_dbus_dict_append_basic(iter, "Netmask",
1406 DBUS_TYPE_STRING, &mask);
1409 if (ipconfig->system->gateway != NULL)
1410 connman_dbus_dict_append_basic(iter, "Gateway",
1411 DBUS_TYPE_STRING, &ipconfig->system->gateway);
1414 void __connman_ipconfig_append_ipv6(struct connman_ipconfig *ipconfig,
1415 DBusMessageIter *iter)
1421 str = __connman_ipconfig_method2string(ipconfig->method);
1425 connman_dbus_dict_append_basic(iter, "Method", DBUS_TYPE_STRING, &str);
1427 if (ipconfig->system == NULL)
1430 if (ipconfig->system->local != NULL) {
1431 connman_dbus_dict_append_basic(iter, "Address",
1432 DBUS_TYPE_STRING, &ipconfig->system->local);
1433 connman_dbus_dict_append_basic(iter, "PrefixLength",
1435 &ipconfig->system->prefixlen);
1438 if (ipconfig->system->gateway != NULL)
1439 connman_dbus_dict_append_basic(iter, "Gateway",
1440 DBUS_TYPE_STRING, &ipconfig->system->gateway);
1443 void __connman_ipconfig_append_ipv6config(struct connman_ipconfig *ipconfig,
1444 DBusMessageIter *iter)
1450 str = __connman_ipconfig_method2string(ipconfig->method);
1454 connman_dbus_dict_append_basic(iter, "Method", DBUS_TYPE_STRING, &str);
1456 switch (ipconfig->method) {
1457 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
1458 case CONNMAN_IPCONFIG_METHOD_OFF:
1459 case CONNMAN_IPCONFIG_METHOD_DHCP:
1461 case CONNMAN_IPCONFIG_METHOD_FIXED:
1462 case CONNMAN_IPCONFIG_METHOD_MANUAL:
1466 if (ipconfig->address == NULL)
1469 if (ipconfig->address->local != NULL) {
1470 connman_dbus_dict_append_basic(iter, "Address",
1471 DBUS_TYPE_STRING, &ipconfig->address->local);
1472 connman_dbus_dict_append_basic(iter, "PrefixLength",
1474 &ipconfig->address->prefixlen);
1477 if (ipconfig->address->gateway != NULL)
1478 connman_dbus_dict_append_basic(iter, "Gateway",
1479 DBUS_TYPE_STRING, &ipconfig->address->gateway);
1482 void __connman_ipconfig_append_ipv4config(struct connman_ipconfig *ipconfig,
1483 DBusMessageIter *iter)
1489 str = __connman_ipconfig_method2string(ipconfig->method);
1493 connman_dbus_dict_append_basic(iter, "Method", DBUS_TYPE_STRING, &str);
1495 switch (ipconfig->method) {
1496 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
1497 case CONNMAN_IPCONFIG_METHOD_OFF:
1498 case CONNMAN_IPCONFIG_METHOD_FIXED:
1499 case CONNMAN_IPCONFIG_METHOD_DHCP:
1501 case CONNMAN_IPCONFIG_METHOD_MANUAL:
1505 if (ipconfig->address == NULL)
1508 if (ipconfig->address->local != NULL) {
1510 struct in_addr netmask;
1513 connman_dbus_dict_append_basic(iter, "Address",
1514 DBUS_TYPE_STRING, &ipconfig->address->local);
1516 addr = 0xffffffff << (32 - ipconfig->address->prefixlen);
1517 netmask.s_addr = htonl(addr);
1518 mask = inet_ntoa(netmask);
1519 connman_dbus_dict_append_basic(iter, "Netmask",
1520 DBUS_TYPE_STRING, &mask);
1523 if (ipconfig->address->gateway != NULL)
1524 connman_dbus_dict_append_basic(iter, "Gateway",
1525 DBUS_TYPE_STRING, &ipconfig->address->gateway);
1528 int __connman_ipconfig_set_config(struct connman_ipconfig *ipconfig,
1529 enum connman_ipconfig_type type, DBusMessageIter *array)
1531 enum connman_ipconfig_method method = CONNMAN_IPCONFIG_METHOD_UNKNOWN;
1532 const char *address = NULL, *netmask = NULL, *gateway = NULL,
1533 *prefix_length_string = NULL;
1534 int prefix_length = 0;
1535 DBusMessageIter dict;
1537 DBG("ipconfig %p type %d", ipconfig, type);
1539 if (type != CONNMAN_IPCONFIG_TYPE_IPV4 &&
1540 type != CONNMAN_IPCONFIG_TYPE_IPV6)
1543 if (dbus_message_iter_get_arg_type(array) != DBUS_TYPE_ARRAY)
1546 dbus_message_iter_recurse(array, &dict);
1548 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
1549 DBusMessageIter entry;
1553 dbus_message_iter_recurse(&dict, &entry);
1555 if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING)
1558 dbus_message_iter_get_basic(&entry, &key);
1559 dbus_message_iter_next(&entry);
1561 type = dbus_message_iter_get_arg_type(&entry);
1563 if (g_str_equal(key, "Method") == TRUE) {
1566 if (type != DBUS_TYPE_STRING)
1569 dbus_message_iter_get_basic(&entry, &str);
1570 method = __connman_ipconfig_string2method(str);
1571 } else if (g_str_equal(key, "Address") == TRUE) {
1572 if (type != DBUS_TYPE_STRING)
1575 dbus_message_iter_get_basic(&entry, &address);
1576 } else if (g_str_equal(key, "PrefixLength") == TRUE) {
1577 if (type != DBUS_TYPE_STRING)
1580 dbus_message_iter_get_basic(&entry,
1581 &prefix_length_string);
1583 prefix_length = atoi(prefix_length_string);
1584 if (prefix_length < 0 || prefix_length > 128)
1587 } else if (g_str_equal(key, "Netmask") == TRUE) {
1588 if (type != DBUS_TYPE_STRING)
1591 dbus_message_iter_get_basic(&entry, &netmask);
1592 } else if (g_str_equal(key, "Gateway") == TRUE) {
1593 if (type != DBUS_TYPE_STRING)
1596 dbus_message_iter_get_basic(&entry, &gateway);
1598 dbus_message_iter_next(&dict);
1601 DBG("method %d address %s netmask %s gateway %s prefix_length %d",
1602 method, address, netmask, gateway, prefix_length);
1605 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
1606 case CONNMAN_IPCONFIG_METHOD_OFF:
1607 case CONNMAN_IPCONFIG_METHOD_FIXED:
1610 case CONNMAN_IPCONFIG_METHOD_MANUAL:
1611 if (address == NULL)
1614 ipconfig->method = method;
1616 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
1617 connman_ipaddress_set_ipv4(ipconfig->address,
1618 address, netmask, gateway);
1620 return connman_ipaddress_set_ipv6(
1621 ipconfig->address, address,
1622 gateway, prefix_length);
1625 case CONNMAN_IPCONFIG_METHOD_DHCP:
1626 if (ipconfig->method == method)
1629 ipconfig->method = method;
1636 void __connman_ipconfig_append_proxy(struct connman_ipconfig *ipconfig,
1637 DBusMessageIter *iter)
1639 struct connman_ipdevice *ipdevice;
1640 const char *method = "direct";
1642 ipdevice = g_hash_table_lookup(ipdevice_hash,
1643 GINT_TO_POINTER(ipconfig->index));
1644 if (ipdevice == NULL)
1647 if (ipdevice->pac == NULL)
1650 method = "auto-config";
1652 connman_dbus_dict_append_basic(iter, "URL",
1653 DBUS_TYPE_STRING, &ipdevice->pac);
1656 connman_dbus_dict_append_basic(iter, "Method",
1657 DBUS_TYPE_STRING, &method);
1660 void __connman_ipconfig_append_proxyconfig(struct connman_ipconfig *ipconfig,
1661 DBusMessageIter *iter)
1663 struct connman_ipdevice *ipdevice;
1664 const char *method = "auto";
1666 ipdevice = g_hash_table_lookup(ipdevice_hash,
1667 GINT_TO_POINTER(ipconfig->index));
1668 if (ipdevice == NULL)
1671 if (ipdevice->proxy == NULL)
1674 method = ipdevice->proxy;
1677 connman_dbus_dict_append_basic(iter, "Method",
1678 DBUS_TYPE_STRING, &method);
1681 int __connman_ipconfig_set_proxyconfig(struct connman_ipconfig *ipconfig,
1682 DBusMessageIter *array)
1684 struct connman_ipdevice *ipdevice;
1685 DBusMessageIter dict;
1688 DBG("ipconfig %p", ipconfig);
1690 ipdevice = g_hash_table_lookup(ipdevice_hash,
1691 GINT_TO_POINTER(ipconfig->index));
1692 if (ipdevice == NULL)
1695 if (dbus_message_iter_get_arg_type(array) != DBUS_TYPE_ARRAY)
1698 dbus_message_iter_recurse(array, &dict);
1700 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
1701 DBusMessageIter entry;
1705 dbus_message_iter_recurse(&dict, &entry);
1707 if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING)
1710 dbus_message_iter_get_basic(&entry, &key);
1711 dbus_message_iter_next(&entry);
1713 type = dbus_message_iter_get_arg_type(&entry);
1715 if (g_str_equal(key, "Method") == TRUE) {
1716 if (type != DBUS_TYPE_STRING)
1719 dbus_message_iter_get_basic(&entry, &method);
1720 if (strlen(method) == 0)
1724 dbus_message_iter_next(&dict);
1727 DBG("method %s", method);
1732 if (g_str_equal(method, "auto") == FALSE &&
1733 g_str_equal(method, "direct") == FALSE)
1736 g_free(ipdevice->proxy);
1737 ipdevice->proxy = g_strdup(method);
1742 void __connman_ipconfig_append_ethernet(struct connman_ipconfig *ipconfig,
1743 DBusMessageIter *iter)
1745 struct connman_ipdevice *ipdevice;
1746 const char *method = "auto";
1748 connman_dbus_dict_append_basic(iter, "Method",
1749 DBUS_TYPE_STRING, &method);
1751 ipdevice = g_hash_table_lookup(ipdevice_hash,
1752 GINT_TO_POINTER(ipconfig->index));
1753 if (ipdevice == NULL)
1756 if (ipdevice->ifname != NULL)
1757 connman_dbus_dict_append_basic(iter, "Interface",
1758 DBUS_TYPE_STRING, &ipdevice->ifname);
1760 if (ipdevice->address != NULL)
1761 connman_dbus_dict_append_basic(iter, "Address",
1762 DBUS_TYPE_STRING, &ipdevice->address);
1764 if (ipdevice->mtu > 0)
1765 connman_dbus_dict_append_basic(iter, "MTU",
1766 DBUS_TYPE_UINT16, &ipdevice->mtu);
1769 int __connman_ipconfig_load(struct connman_ipconfig *ipconfig,
1770 GKeyFile *keyfile, const char *identifier, const char *prefix)
1775 DBG("ipconfig %p identifier %s", ipconfig, identifier);
1777 key = g_strdup_printf("%smethod", prefix);
1778 method = g_key_file_get_string(keyfile, identifier, key, NULL);
1779 if (method == NULL) {
1780 if (ipconfig->type == CONNMAN_IPCONFIG_TYPE_IPV4)
1781 ipconfig->method = CONNMAN_IPCONFIG_METHOD_DHCP;
1783 ipconfig->method = CONNMAN_IPCONFIG_METHOD_OFF;
1785 ipconfig->method = __connman_ipconfig_string2method(method);
1788 key = g_strdup_printf("%snetmask_prefixlen", prefix);
1789 ipconfig->address->prefixlen = g_key_file_get_integer(
1790 keyfile, identifier, key, NULL);
1793 key = g_strdup_printf("%slocal_address", prefix);
1794 ipconfig->address->local = g_key_file_get_string(
1795 keyfile, identifier, key, NULL);
1798 key = g_strdup_printf("%speer_address", prefix);
1799 ipconfig->address->peer = g_key_file_get_string(
1800 keyfile, identifier, key, NULL);
1803 key = g_strdup_printf("%sbroadcast_address", prefix);
1804 ipconfig->address->broadcast = g_key_file_get_string(
1805 keyfile, identifier, key, NULL);
1808 key = g_strdup_printf("%sgateway", prefix);
1809 ipconfig->address->gateway = g_key_file_get_string(
1810 keyfile, identifier, key, NULL);
1816 int __connman_ipconfig_save(struct connman_ipconfig *ipconfig,
1817 GKeyFile *keyfile, const char *identifier, const char *prefix)
1822 DBG("ipconfig %p identifier %s", ipconfig, identifier);
1824 method = __connman_ipconfig_method2string(ipconfig->method);
1826 key = g_strdup_printf("%smethod", prefix);
1827 g_key_file_set_string(keyfile, identifier, key, method);
1830 key = g_strdup_printf("%snetmask_prefixlen", prefix);
1831 g_key_file_set_integer(keyfile, identifier,
1832 key, ipconfig->address->prefixlen);
1835 key = g_strdup_printf("%slocal_address", prefix);
1836 if (ipconfig->address->local != NULL)
1837 g_key_file_set_string(keyfile, identifier,
1838 key, ipconfig->address->local);
1841 key = g_strdup_printf("%speer_address", prefix);
1842 if (ipconfig->address->peer != NULL)
1843 g_key_file_set_string(keyfile, identifier,
1844 key, ipconfig->address->peer);
1847 key = g_strdup_printf("%sbroadcast_address", prefix);
1848 if (ipconfig->address->broadcast != NULL)
1849 g_key_file_set_string(keyfile, identifier,
1850 key, ipconfig->address->broadcast);
1853 key = g_strdup_printf("%sgateway", prefix);
1854 if (ipconfig->address->gateway != NULL)
1855 g_key_file_set_string(keyfile, identifier,
1856 key, ipconfig->address->gateway);
1862 int __connman_ipconfig_init(void)
1866 ipdevice_hash = g_hash_table_new_full(g_direct_hash, g_direct_equal,
1867 NULL, free_ipdevice);
1872 void __connman_ipconfig_cleanup(void)
1876 g_hash_table_destroy(ipdevice_hash);
1877 ipdevice_hash = NULL;